Skip to main content

Web mercator XYZ tile utilities

Project description

Build Status Coverage Status Documentation Status

Spherical mercator coordinate and tile utilities

Documentation: http://mercantile.readthedocs.io/en/latest/

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, a tile(lng, lat, zoom) function that returns the tile containing a given point, and quadkey conversion functions quadkey(xtile, ytile, zoom) and quadkey_to_tile(quadkey) for translating between quadkey and tile coordinates.

>>> 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.xy_bounds(486, 332, 10)
Bbox(left=-1017529.7205322663, bottom=7005300.768279833, right=-978393.962050256, top=7044436.526761846)
>>> mercantile.tile(*mercantile.ul(486, 332, 10) + (10,))
Tile(x=486, y=332, z=10)
>>> mercantile.quadkey(486, 332, 10)
'0313102310'
>>> mercantile.quadkey_to_tile('0313102310')
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 --help
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:
  bounding-tile  Print the bounding tile of a lng/lat point, bounding box, or
                 GeoJSON objects.
  children       Print the children of the tile.
  parent         print the parent tile.
  quadkey        Convert to/from quadkeys.
  shapes         Print the shapes of tiles as GeoJSON.
  tiles          Print 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

supermercado is another python lib with added tile logic functionality (union tile shapes, find edge tiles, and find tile intersections for complex geometries).

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-1.1.2.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

mercantile-1.1.2-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mercantile-1.1.2.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for mercantile-1.1.2.tar.gz
Algorithm Hash digest
SHA256 6681c0be3b3d8ea1d88d7f9cff56993782fb7de1e9df420ad9c48f93a859394d
MD5 808d7a7a8351e1b795954f9c61dc0f1f
BLAKE2b-256 aade0b61f5fb37e64e2bc37f0beb7267777f8b30b91d5fbdecf1c05a3a472f6f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mercantile-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for mercantile-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6ef7301b8f5b29f622b97f5ab2c43edfa2e1c3857b96adbfc6eac9ec376abe0e
MD5 aaf84d24bed8fbe3ea10d153dbe95b44
BLAKE2b-256 9d1d80d28ba17e4647bf820e8d5f485d58f9da9c5ca424450489eb49e325ba66

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