Skip to content

A backend component for location-based and real-time applications. Based on the current location of a user this backend component can be used to determine if a person is inside a building or not.

License

Notifications You must be signed in to change notification settings

NicklasXYZ/Geolocator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geolocator Component

illu

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:

  1. Given a location in terms of longitude and latitude in decimal degrees, geohash the location using a Hilbert space-filling curve.
  2. 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.
  3. 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 the k returned geospatial features from Redis.
  4. 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.

Usage

  1. Set appropriate values in the overpass.env file
  2. Build and start the Redis and Overpass docker containers with docker-compose:
docker-compose up
  1. Install python dependencies:
pip install -r requirements.txt
  1. See examples in the jupyter notebook: html or .ipynb

About

A backend component for location-based and real-time applications. Based on the current location of a user this backend component can be used to determine if a person is inside a building or not.

Topics

Resources

License

Stars

Watchers

Forks