Skip to content

Instantly share code, notes, and snippets.

@maiquelleonel
Last active October 26, 2020 15:47
Show Gist options
  • Save maiquelleonel/a925af19e8c7e87b48b46cbf344237de to your computer and use it in GitHub Desktop.
Save maiquelleonel/a925af19e8c7e87b48b46cbf344237de to your computer and use it in GitHub Desktop.
calc if given geopoint (lat, lng) is inside a polygon
def inside_polygon(point, polygon):
lat, lng = point
inside = False
for index, geo_point in enumerate(polygon):
lat_i, lng_i = geo_point
lat_j, lng_j = polygon[index -1]
if (lat_i < lat and lat_j >= lat) or (lat_j < lat and lat_i >= lat):
if lng > lng_i + (lat * ((lng_j - lng_i)/(lat_j - lat_i))):
inside = not inside
return inside
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment