Skip to main content

Spherical mercator and XYZ tile utilities

Project description

Spherical mercator coordinate and tile utilities

The mercantile module provides ul(xtile, ytile, zoom) and bounds(xtile, ytile, zoom) functions that return longitudes and latitudes for XYZ tiles, and a xy(lon, lat) function that returns spherical mercator x and y coordinates.

>>> import mercantile
>>> mercantile.ul(486, 332, 10)
(-9.140625, 53.33087298301705)
>>> mercantile.bounds(486, 332, 10)
(-9.140625, 53.12040528310657, -8.7890625, 53.33087298301705)
>>> mercantile.xy(*mercantile.ul(486, 332, 10))
(-1017529.7205322663, 7044436.526761846)

Mercantile CLI

Mercantile’s command line interface, named “mercantile”, has commands for getting the shapes of Web Mercator tiles as GeoJSON and getting the tiles that intersect with a GeoJSON bounding box. They can be combined like this:

$ echo "[-104.99, 39.99, -105, 40]" \
> | mercantile tiles - 14 \
> | mercantile shapes -
{"features": [{"geometry": {"coordinates": [[[-105.00732421875, 39.9939556939733], [-105.00732421875, 40.01078714046552], [-104.9853515625, 40.01078714046552], [-104.9853515625, 39.9939556939733], [-105.00732421875, 39.9939556939733]]], "type": "Polygon"}, "id": "(3413, 6202, 14)", "properties": {"title": "XYZ tile (3413, 6202, 14)"}, "type": "Feature"}, {"geometry": {"coordinates": [[[-105.00732421875, 39.977120098439634], [-105.00732421875, 39.9939556939733], [-104.9853515625, 39.9939556939733], [-104.9853515625, 39.977120098439634], [-105.00732421875, 39.977120098439634]]], "type": "Polygon"}, "id": "(3413, 6203, 14)", "properties": {"title": "XYZ tile (3413, 6203, 14)"}, "type": "Feature"}], "type": "FeatureCollection"}

If you have geojsonio-cli installed, you can shoot this GeoJSON straight to geojson.io for lightning-fast visualization and editing.

$ echo "[-104.99, 39.99, -105, 40]" \
> | mercantile tiles - 14 \
> | mercantile shapes - --compact \
> | geojsonio

See Also

node-sphericalmercator provides many of the same features for Node.

Project details


Release history Release notifications

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

1.0b2

History Node

1.0b1

History Node

1.0a1

History Node

0.11.0

History Node

0.10.0

History Node

0.9.0

History Node

0.8.3

History Node

0.8.2

History Node

0.8.1

History Node

0.8

History Node

0.7.1

History Node

0.7

History Node

0.6.1

History Node

0.6

History Node

0.5.1

History Node

0.5

History Node

0.4

History Node

0.3

History Node

0.2.1

This version
History Node

0.2

History Node

0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
mercantile-0.2.tar.gz (5.1 kB) Copy SHA256 hash SHA256 Source None Aug 19, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page