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.2.1.tar.gz (49.4 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.2.1-py3-none-any.whl (48.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stapel_geo-0.2.1.tar.gz
  • Upload date:
  • Size: 49.4 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.2.1.tar.gz
Algorithm Hash digest
SHA256 32aa554b6f580f5bc077a23f6ac7485e1297d10f521efb2c6c0374fc41cae2e8
MD5 fa0a862f66083f9fd2983c2f95df441b
BLAKE2b-256 674a94e69bef1762d3cdfefc44fdde24cfd918aa3c5ff3c0c81116e254ef39ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for stapel_geo-0.2.1.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.2.1-py3-none-any.whl.

File metadata

  • Download URL: stapel_geo-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 48.6 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 39f567f926cfdb656effe7e7a84a13dccadb38fc6150c45c5f485e67ad0f38a0
MD5 bfb8a9818c3d17f2fcd1f62657214885
BLAKE2b-256 6e4a52c4765e883422a3ae52486e769db76e348012500eb353e8dade0e86fa78

See more details on using hashes here.

Provenance

The following attestation bundles were made for stapel_geo-0.2.1-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