Skip to main content

Spherical mercator and XYZ tile utilities

Project description

https://travis-ci.org/mapbox/mercantile.svg

Spherical mercator coordinate and tile utilities

The mercantile module provides ul(xtile, ytile, zoom) and bounds(xtile, ytile, zoom) functions that respectively return the upper left corner and bounding longitudes and latitudes for XYZ tiles, a xy(lng, lat) function that returns spherical mercator x and y coordinates, and a tile(lng, lat, zoom) function that returns the tile containing a given point.

>>> import mercantile
>>> mercantile.ul(486, 332, 10)
LngLat(lng=-9.140625, lat=53.33087298301705)
>>> mercantile.bounds(486, 332, 10)
LngLatBbox(west=-9.140625, south=53.12040528310657, east=-8.7890625, north=53.33087298301705)
>>> mercantile.xy(*mercantile.ul(486, 332, 10))
(-1017529.7205322663, 7044436.526761846)
>>> mercantile.tile(*mercantile.ul(486, 332, 10) + (10,))
Tile(x=486, y=332, z=10)

Also in mercantile are functions to traverse the tile stack.

>>> mercantile.parent(486, 332, 10)
Tile(x=243, y=166, z=9)
>>> mercantile.children(mercantile.parent(486, 332, 10))
[Tile(x=486, y=332, z=10), Tile(x=487, y=332, z=10), Tile(x=487, y=333, z=10), Tile(x=486, y=333, z=10)]

Named tuples are used to represent tiles, coordinates, and bounding boxes.

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.

$ mercantile
Usage: mercantile [OPTIONS] COMMAND [ARGS]...

  Command line interface for the Mercantile Python package.

Options:
  -v, --verbose  Increase verbosity.
  -q, --quiet    Decrease verbosity.
  --help         Show this message and exit.

Commands:
  children  Write the children of the tile.
  parent    Write the parent tile.
  shapes    Write the shapes of tiles as GeoJSON.
  tiles     List tiles that overlap or contain a lng/lat point, bounding box,
            or GeoJSON objects.

See docs/cli.rst for more about the mercantile program.

See Also

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

tilebelt has some of the GeoJSON features as mercantile and a few more (tile parents, quadkey).

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

mercantile-0.8.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distributions

mercantile-0.8.3-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

mercantile-0.8.3-py2-none-any.whl (10.0 kB view details)

Uploaded Python 2

File details

Details for the file mercantile-0.8.3.tar.gz.

File metadata

  • Download URL: mercantile-0.8.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mercantile-0.8.3.tar.gz
Algorithm Hash digest
SHA256 761dc450be5cf3b276d201a25943acca64c638ed45f1636d8015e6f793143103
MD5 600f3faf0a03e17d34b7d0cf095c1dcd
BLAKE2b-256 197ab75e52ab5d0f0fedf5c3958576db60545c52ccd86c5fcd3e1407c2e81d27

See more details on using hashes here.

File details

Details for the file mercantile-0.8.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mercantile-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8e0c4b9768c27ad7e43c3b99c605ebac0a5fe99f9f2c4877e1a4995097e19abd
MD5 1753cd65c2ac16abf12c7496fa48ae3c
BLAKE2b-256 ea84e8070aac3ae2db04a5a1669d56149a9703dd6a43ee76515963259cffa299

See more details on using hashes here.

File details

Details for the file mercantile-0.8.3-py2-none-any.whl.

File metadata

File hashes

Hashes for mercantile-0.8.3-py2-none-any.whl
Algorithm Hash digest
SHA256 1ffd7ba787af09601e6024caadd82fd3afb63485523df3f911b17724fec6b2b3
MD5 df3cec75cc726d33ccc27d72aec8bd0f
BLAKE2b-256 5035a6503481b284a1ff34d1f9a6e2d248770ee39792c065b4a0d781dc8efc63

See more details on using hashes here.

Supported by

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