This repository contains a python script along with a configured stack of technologies (Overpass and Redis) that makes it possible to efficiently determine whether a given point in space is close to or contained in another geospatial feature, such as a polygon. In other words, we can determine if a location is inside or close to e.g. a building.
See the following for a brief overview of how the python script and technology stack work:
- Given a location in terms of longitude and latitude in decimal degrees, geohash the location using a Hilbert space-filling curve.
- Use the computed geohash as a key to check in Redis if a sorted set of geospatial features have been cached for the bounding box encoded by the geohash.
- If the key exists then use the given location to query the
k
closest geospatial features in the sorted set and use the shapely python library to determine if the given location is contained in one of thek
returned geospatial features from Redis. - If the key does not exist in Redis, then build a query to OpenStreeMap's Overpass API to retrieve all geospatial features in the bounding box encoded by the geohash. Cache the returned data from Overpass in Redis by using the geohash as key, then use shapely to determine if the given location is contained in one of the geospatial features returned from Overpass.
Note: Sorted sets of geospatial features are regularly purged from Redis based on a user-defined time-to-live (ttl) value. This is done to make sure stale data from Overpass do not accumulate, stay in cache and take up too much unnecessary memory.
- Set appropriate values in the
overpass.env
file - Build and start the Redis and Overpass docker containers with docker-compose:
docker-compose up
- Install python dependencies:
pip install -r requirements.txt