Last active
October 26, 2020 15:47
-
-
Save maiquelleonel/a925af19e8c7e87b48b46cbf344237de to your computer and use it in GitHub Desktop.
calc if given geopoint (lat, lng) is inside a polygon
This file contains 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
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