GIS CUP 2013
Geo - Fencing ● Virtual perimeter for a real world geographic area ● Widely used in location based services ● Location based advertisements ● Child Location services
Problem Definition ● Input : Set of Regions ( May be overlapping) ● Set of Points ( ID and Sequence) ● Output : Pair each input point with one or more regions on the satisfaction of spatial condition between them ● Spatial conditions ● INSIDE ● WITH IN
INSIDE ● TRUE - if a point is inside the polygon ● The point can be associated with one or more polygons ● A point can be INSIDE any polygon with a sequence number (i.e., timestamp) less than the sequence number of the point where only the latest position of each polygon (up to that sequence number) is considered.
Point in Polygon Algorithm ● Compare each side of the polygon to the Y (vertical) coordinate of the test point, and compile a list of nodes, where each node is a point where one side crosses the Y threshold of the test point ● Arbitrarily decide that points on the Y threshold will belong to the “above” side of the threshold ● In Above figure, eight sides of the polygon cross the Y threshold, while the other six sides do not ● Odd number of nodes on each side of the test point - inside the polygon ● Even number - outside the polygon.
● Polygon Crosses itself ● The effect is much like “exclusive or”. The portions of the polygon which overlap cancel each other out. ● So, the test point is outside the polygon ● Even number of nodes (two and two) on either side of it.
● The six-sided polygon does not overlap itself, but it does have lines that cross. ● Not a problem; the algorithm still works fine.
● A vertex of the polygon falls directly on the Y threshold (fig 1) ● One of its sides lies entirely on the threshold ( fig 2) ● Not a problem; the algorithm still works fine.
PIP Variables ● Global Variables ● int polysides; ● float polyX[]; ● float polyY[]; ● float x,y;
PIP Algorithm bool pointInPolygon() { int i, j=polySides-1 ; bool oddNodes=NO ; for (i=0; i<polySides; i++) { if ((polyY[i] =y || polyY[j] =y) && (polyX[i]<=x || polyX[j]<=x)) { oddNodes^=(polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x); } j=i; } return oddNodes; }
Within ● True – if the point is at less than 1000 units distance from the polygon ● Each point may be associated with one or more of the polygons, as the same point can be within 1000 units distance from several polygons.
With in Algorithm ● Finding the distance between every polygon edge and test point ● Check If there exists any polygon edge with 1000 units distance from test point ● Distance calculation
Algorithm ● Start ● Read Predicate value from user ● For every test Point { ● { For every Polygon, ● If( Point sequence> Polygon sequence) ● PIP algorithm or With in Algorithm ● } ● Return point id sequence with their associating polygon or YES/ NO if point with in 1000 units ● Stop ●
Cost analysis ● Time complexity ● Pre processing – O(N) ● Processing – May be O(Log N) ● Accuracy – works well with convex/ concave polygons. ● Not sure for points on the polygons ● Still working on that!
Thank you!!!