Skip to main content

Geographic locations and geocoding for the Stapel framework

Project description

stapel-geo

Geographic locations and geocoding for the Stapel framework — composable Django apps that deploy as a monolith or as microservices without changing module code.

  • Location tree — hierarchical places (GeoDjango + treenode) with GADM boundaries, centroid geohash, and cross-service UUIDs.
  • GADM import — upload GeoJSON extracts; a status machine streams them into the tree with progress + a completion event.
  • Geohash proximity — nearby-by-coordinates / nearby-by-geohash.
  • Geocoder proxy — forward / structured / reverse geocoding behind a swappable provider seam (Photon by default).

Install

pip install stapel-geo          # geohash math, geocoder proxy, comm surface
pip install "stapel-geo[geo]"   # + the spatial layer (needs GDAL + a spatial DB)

The location tree, GADM import and admin need the GDAL C library and a spatial database (PostGIS in production, SpatiaLite for tests). The geohash math, geocoder proxy, comm Functions and settings work without GDAL.

INSTALLED_APPS = [
    # ...
    "django.contrib.gis",   # only if you use the spatial layer
    "stapel_geo",
]

# urls.py
path("geo/", include("stapel_geo.urls"))
# ... or mount only the GDAL-free geocoder proxy:
path("geo/geocoding/", include("stapel_geo.geocoding.urls"))

Before the first spatial migration in production:

python manage.py enable_postgis
python manage.py load_geofiles --folder /path/to/gadm

Settings (STAPEL_GEO)

Key Default Meaning
GEOCODER …providers.PhotonGeocoder Geocoder provider class (dotted path).
PHOTON_URL http://localhost:2322 Photon base URL (default provider).
PHOTON_LANGUAGES ["default","en","de","fr"] Indexed languages; others fall back to en.
GEOCODER_TIMEOUT 10 Geocoder HTTP timeout (s).
GEOHASH_PRECISION 8 Stored centroid geohash precision.
NEARBY_PRECISION 6 Default precision for coordinate nearby search.
NEARBY_LIMIT / NEARBY_MAX_LIMIT 10 / 50 Default / max nearby results.
SIMPLIFY_MAX_POINTS 100 fast_centroid simplification budget.
GADM_FOLDER /app/geofiles Folder load_geofiles scans.
IMPORT_ASYNC True Background GADM import + geo.import.completed emit.

comm surface

Kind Name Contract
Function geo.nearby {lat,lon}/{geohash} [,limit]{results:[…]}
Function geo.resolve {uuid}{found, …}
Action geo.import.completed {geofile_id, location_level, feature_count, status}
from stapel_core.comm import call
call("geo.nearby", {"lat": 49.61, "lon": 6.13, "limit": 5})

GADM data & geocoder providers

The wheel ships only a tiny sample extract — hosts supply their own GADM data (see geofiles/README.md; non-commercial license). Swap the geocoder by implementing the Geocoder ABC and setting STAPEL_GEO["GEOCODER"].

See MODULE.md for every fork-free seam.

Development

pip install -e . && pip install pytest pytest-django ruff pytest-cov
./setup-hooks.sh
pytest tests/    # spatial tests skip-with-reason without GDAL

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stapel_geo-0.1.0.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stapel_geo-0.1.0-py3-none-any.whl (57.1 kB view details)

Uploaded Python 3

File details

Details for the file stapel_geo-0.1.0.tar.gz.

File metadata

  • Download URL: stapel_geo-0.1.0.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stapel_geo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed493b7241c7e411ca1c74693e7e5a7b4b3b37c661aa35cc87e32a7ec9748a0c
MD5 c9b6968f6f85cc03cd202f9e5b090198
BLAKE2b-256 c66e05d88e2ef8c57090b0d2ec8ecd89c05330e28c4d61b8295ded0eb0fe0341

See more details on using hashes here.

Provenance

The following attestation bundles were made for stapel_geo-0.1.0.tar.gz:

Publisher: publish.yml on usestapel/stapel-geo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stapel_geo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: stapel_geo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 57.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stapel_geo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f7bb4d58dfcb956de7ee58e8f23cedcc7847ce89a8cbd8aa66771ed0ac5a980
MD5 e04fd50a49bfcf48479e80c83683bc5d
BLAKE2b-256 6e62ee8dcb0613a973dfe8a632c39bb46539df3380b93980527a40ac434ae060

See more details on using hashes here.

Provenance

The following attestation bundles were made for stapel_geo-0.1.0-py3-none-any.whl:

Publisher: publish.yml on usestapel/stapel-geo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page