Mercantile

1.2.1 · active · verified Sat Apr 11

Mercantile is a Python library (current version 1.2.1) providing utilities for working with Web Mercator XYZ tiles. It offers functions to convert between geographic coordinates (longitude, latitude) and tile coordinates (x, y, z), calculate tile bounds, and traverse the tile hierarchy (parent, children, neighbors). Releases occur periodically, with significant updates every 1-2 years.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates fundamental operations: getting a tile for a given point, retrieving its geographic bounds, finding its upper-left corner, and identifying its children tiles.

import mercantile

# Get the tile containing a specific longitude, latitude, and zoom level
tile = mercantile.tile(-105.0, 40.0, 10)
print(f"Tile: {tile}")

# Get the geographic (longitude and latitude) bounds of a tile
bbox = mercantile.bounds(tile.x, tile.y, tile.z)
print(f"Bounding Box: {bbox}")

# Get the upper-left corner (longitude, latitude) of a tile
ul_corner = mercantile.ul(tile.x, tile.y, tile.z)
print(f"Upper-Left Corner: {ul_corner}")

# Find children tiles at a deeper zoom level
children_tiles = mercantile.children(tile, zoom=11)
print(f"Children tiles (first 2): {children_tiles[:2]}")

view raw JSON →