Skip to main content

Tile Tools

Python Tests Python Lint

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.

Contents

tilebelt

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.

cover

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.

coords

coords.tilecoords2lnglat

Transform Mapbox's relative tile (x, y) coordinates into longitude/latitude degrees.

distance

distance.haversine

Compute the distance between two points on the globe using the haversine formula.

Rendering

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

Development

Set up the environment with poetry:

poetry install --with dev
poetry run pre-commit install

Tests

poetry run pytest

Release files for tile-tools 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tile-tools 0.1.2
File Size Uploaded
tile_tools-0.1.2.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tile-tools 0.1.2
File Interpreter ABI Platform
tile_tools-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / tile_tools-0.1.2.tar.gz

Download URL tile_tools-0.1.2.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d92dcbd04fd1109a60c65e2ad64096e29b9fa775ac44df3023e69535bfeb1caa
BLAKE2b-256 checksum
How to use checksums
b4a51dafe766a26e0aaca6826093983dd8adab36c9ad6d678ce8fcc78fcf9981
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.9 Darwin/21.4.0

Release files / tile_tools-0.1.2-py3-none-any.whl

Download URL tile_tools-0.1.2-py3-none-any.whl
Size 20.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2379f0613a3b1ce8213b4bb85fc53f13b170133b775ec3e597207c9376278666
BLAKE2b-256 checksum
How to use checksums
36be1a63eb0840de3044fc2f2a6f6fca651c9c541d5f5314fd029f5dfb3ab373
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.9 Darwin/21.4.0

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page