Collection of tools useful for navigating Mapbox (and similar) tiles.
Most of these tools were written by Mapbox in JavaScript. I've ported them into Python with minimal modification.
Utility functions for working with tiles.
This is a complete Python port of Mapbox's @mapbox/tilebelt.
There are some minor differences in the API. See the submodule readme for more details.
Given a GeoJSON Geometry and a zoom level, generate the minimal set of Mapbox (x, y, zoom)
tiles that cover this geometry.
This is a re-implementation of Mapbox's @mapbox/tile-cover
.
The implementation started out as a port, however the originally library is not passing all of its own tests.
The API has been re-implemented here with a slightly different approach, and all of the equivalent tests are now passing.
See submodule readme for details.
Transform Mapbox's relative tile (x, y)
coordinates into longitude/latitude degrees.
Compute the distance between two points on the globe using the haversine formula.
For debugging and general interest, the cover algorithm can be visualized with the scripts/render.py
script.
It requires that gdal
and ImageMagick
are installed. Then, run:
poetry install --with render
An example usage is rendering the degenring
test fixture at zooms 1-14.
The output will be stored as a GIF in render.gif
.
cat tests/fixtures/degenring.geojson | poetry run python scripts/render.py --zmin 1 --zmax 13 --out render.gif
Set up the environment with poetry
:
poetry install --with dev
poetry run pre-commit install
poetry run pytest