Article copyright by the author Xiaohui and blog Garden Common, if reproduced please mark the source clearly: http://www.cnblogs.com/naaoveGIS/. 1. Background
In the Leting project, the engineering colleagues put forward the need in the docking vehicle GPS reporting point, can real-time determine whether the point in the Leting administrative region. If it is not, alert it.
Processing ideas are divided into two kinds, one is the front-end real-time from the database pull into the GPS point, and then determine whether the point is falling in the region surface. The second is in the real-time docking with GPS data, GPS data to our database in the corresponding table, the point is whether to fall in the area of the judgment, if not, the corresponding table in the judgment point-surface relationship field in the label.
Taking into account the efficiency and the preservation of records, the last choice of the second option, that is, at the database level to operate, and save the way to record. 2. The algorithm to judge the point-plane relation 2.1 Algorithm Selection
The algorithm for judging the point-surface relationship is generally as follows:
A difference multiplication method (for convex polygons only)
B. Area discrimination method (for convex polygons only)
C. Angle and discriminant method, etc. (freeform polygon can be)
In order to achieve the universality of the stored procedure, it is more suitable to choose the use angle and discriminant method. 2.2 Principle of angle and discriminant method
Principle: Make P={p1,p2,..., pn,p1} is a vertex pi (xi,yi), i=1,2,..., N closed-Polygon, PT is a test point. The PTPI is a vector connecting pt and pi, αi the angle between the vector ptpi to the ptpi+1.
If Σαi = 0 pt is outside of P;
If Σαi =±2πpt is inside p. 3. Implement the algorithm with stored procedure 3.1 Single angle gain (angle αi algorithm)
3.2 angle sum discriminant
3. Algorithm optimization
The above angle and algorithm is relatively time-consuming, if we judge the point of the relationship before the simplest way to do a filter, so that only meet the requirements of the point of view and algorithm to judge, will be more helpful to efficiency tips.
Here, you can filter the point by using the square coordinates of the range directly at the time you get it.
4. Algorithm Test
Because the GPS has a certain error range, the Leting boundary is extended to some extent. The scope of the extension is then converted into a ring-formatted JSON-dotted string. Then select multiple points to test.
Repeated testing of multiple samples is in line with the requirements.