Created
October 14, 2011 21:00
-
-
Save ajokela/1288325 to your computer and use it in GitHub Desktop.
Is Point within Polygon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GeoHelper.IsInPolygon=function(points,latlong) | |
{ | |
// This code adapted from the following URL: | |
// http://msdn.microsoft.com/en-us/library/cc451895.aspx | |
var i; | |
var j=points.length-1; | |
var inPoly=false; | |
var lat = latlong.Latitude; | |
var lon = latlong.Longitude; | |
for (i=0; i<points.length; i++) | |
{ | |
if (points[i].Longitude<lon && points[j].Longitude>=lon || points[j].Longitude<lon && points[i].Longitude>=lon) | |
{ | |
if (points[i].Latitude+(lon-points[i].Longitude)/(points[j].Longitude-points[i].Longitude)*(points[j].Latitude-points[i].Latitude)<lat) | |
{ | |
inPoly=!inPoly; | |
} | |
} | |
j=i; | |
} | |
return inPoly; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment