Telematics - the electronic fence technology

What is the car electronic fence

Generally speaking, the electronic fence is a good manager delineated in advance of a regular or irregular area can be divided according to administrative areas, such as Beijing, Guangdong and so on.

Its purpose is to facilitate the management: the vehicle leaving the designated area, the system according to the conditions set in advance, start the associated handler, timely alerts and push notifications to mobile phone side will be the team manager.

work process

  1. On-board equipment required to install GPS devices, and can locate the current position in real-time active reporting.
  2. Managers set in the TSP system in which the vehicle is traveling in a designated area, and work out when the vehicle leaves the designated area solutions.
  3. Vehicle transmission of the current vehicle position information TSP system, the system stores the position data of the vehicle and w and analyzed in real time, and records the backup path of travel of the vehicle through the 4G / 5G communication network.
  4. If the vehicle leaves the designated area is set, TSP also push an alarm system is to notify to the manager.

Electronic fence algorithm

1. ray method

Generally polygonal geofence, how to determine the point within the polygon it? May be determined by a point is inside a polygon ray method. As shown below, the starting point from which to draw a ray along the X axis, the intersection of the ray successively determining each side, and counts the number of intersections, if the number of intersections is odd, the internal polygon (FIG. 3 intersections ), the number is even if the focus is on the outside, ray projections and method are applicable to non-convex polygon, complexity is O (N).

2. The angle and method

Figure 1.4, in a polygonal or a little outside, that these are connected to the respective corners of the polygon, angle configuration, is <1 <2 <3 <4 <5 and <6, the phase angle between these and then added to give an angle, for convenience, is referred to this and the angle a. Predetermined forward the clockwise rotation direction, negative in the counterclockwise direction [4]. When a! When = 2π, were determined points outside the polygon; when a = 2π, were determined points inside the polygon.

Inclination method can be used only convex polygons, but is changing the shape of the fence, it may be a convex polygon may also be a concave polygon. From the breadth of the problem, the ray method is the most suitable method.

The sample code

import json
import math
lnglatlist = []

data = '[{"points":[{"lng":0,"lat":0},{"lng":2,"lat":0},{"lng":0,"lat":2}]}]'

data = json.loads(data)
if 'points' in data[0]:
    for point in data[0]['points']:
        lnglat = []
        lnglat.append(float(str(point['lng'])))
        lnglat.append(float(str(point['lat'])))
        lnglatlist.append(lnglat)

def windingNumber(point, poly):
    poly.append(poly[0])
    px = point[0]
    py = point[1]
    sum = 0
    length = len(poly)-1

    for index in range(0,length):
        sx = poly[index][0]
        sy = poly[index][1]
        tx = poly[index+1][0]
        ty = poly[index+1][1]

        #点与多边形顶点重合或在多边形的边上
        if((sx - px) * (px - tx) >= 0 and (sy - py) * (py - ty) >= 0 and (px - sx) * (ty - sy) == (py - sy) * (tx - sx)):
            return "on"
        #点与相邻顶点连线的夹角
        angle = math.atan2(sy - py, sx - px) - math.atan2(ty - py, tx - px)
        #确保夹角不超出取值范围(-π 到 π)
        if(angle >= math.pi):
            angle = angle - math.pi * 2
        elif(angle <= -math.pi):
            angle = angle + math.pi * 2
        #计算回转数并判断点和多边形的几何关系
    result = 'out' if int(sum / math.pi) == 0 else 'in'
    return result

point = [1, 1]
print(windingNumber(point,lnglatlist))

More Reference >> electronic fence technology explain

Guess you like

Origin www.cnblogs.com/xtuz/p/11670973.html