Skip to content

Instantly share code, notes, and snippets.

@korenmiklos
Last active June 2, 2020 20:10
Show Gist options
  • Save korenmiklos/07acaae46a1c09dc2a121490eafc1393 to your computer and use it in GitHub Desktop.
Save korenmiklos/07acaae46a1c09dc2a121490eafc1393 to your computer and use it in GitHub Desktop.
Example illustrating geospatial concepts in Python
from shapely.geometry import Point
# suppose function projection(lat, lon) is already defined, returing (x, y) in meters
neighborgood_gps = (48.2176956, 16.3901985)
# a list of GPS coordinate pairs
transitstops_gps = [(), (), ..., ()]
neighborhood_shapely = Point(projection(neighborgood_gps))
for point in transitstops_gps:
# first project to equidistant coordinates. then create a shapely Point. then measure distance to existing shapely Point.
distance = Point(projection(point)).distance(neighborhood_shapely)
print(distance)
closest_stops = [stop['neighbourhood'] for stop in berlin_data if distance(stop, hotel) < 1.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment