XYZ tiles¶
Web Mercator XYZ tiles, quadkeys, tile hierarchies, and area covers.
Related: Grid-generic API
Types¶
Tile
¶
Accepted call forms
Tile(value: Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str, /) -> Tile
Tile(*, lon: FloatScalar | ScalarFloatArray, lat: FloatScalar | ScalarFloatArray, zoom: int | integer[Any]) -> Tile
Tile(*, x: int | integer[Any], y: int | integer[Any], zoom: int | integer[Any]) -> Tile
One XYZ web-mercator tile: the slippy-map z/x/y address.
Wraps the tile with typed accessors (tile.zoom/x/y,
tile.token, tile.polygon, tile.center) and hierarchy
moves (parent/children/neighbors). The token is the Bing
quadkey (empty at z0); the 64-bit id packs (zoom, Morton x/y)
so sorted ids group spatial neighbors. Convert via Tile(value),
Tile(Point(...), zoom=...), Tile(lon=..., lat=..., zoom=...), or
Tile(x=..., y=..., zoom=...). Coordinate frames are always named.
Geographic point ownership follows the emitted binary64 tile boundaries,
with longitude west-inclusive/east-exclusive and latitude
north-inclusive/south-exclusive ties. This is a representational boundary
contract, not a claim of exact ideal-transcendental Web Mercator rounding.
One XYZ tile from a packed id, quadkey, lon/lat keywords, point geometry,
or explicit x=/y= tile coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | Point
|
A tile id/quadkey, or a point geometry when paired with |
varies by call form
|
zoom
|
int | integer[Any]
|
Zoom level ( |
varies by call form
|
lon
|
FloatScalar | ScalarFloatArray
|
Geographic coordinates, supplied together with |
varies by call form
|
lat
|
FloatScalar | ScalarFloatArray
|
Geographic coordinates, supplied together with |
varies by call form
|
x
|
int | integer[Any]
|
Explicit tile column/row (keyword-only, with |
varies by call form
|
y
|
int | integer[Any]
|
Explicit tile column/row (keyword-only, with |
varies by call form
|
Returns:
| Type | Description |
|---|---|
Tile
|
|
Raises:
| Type | Description |
|---|---|
ParseError
|
If |
GeometryError
|
If |
InvalidGeometryError
|
If a scalar coordinate is non-finite or out of range. |
morton
property
¶
morton: int
The Morton (Z-order) index of x/y within this zoom.
Returns:
| Type | Description |
|---|---|
int
|
|
children
¶
Child cells at a finer zoom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zoom
|
int
|
Target zoom; must not be coarser than this cell's. Defaults to one finer than this cell's zoom; a maximum-depth cell has no children and yields an empty CellArray. |
None
|
Returns:
| Type | Description |
|---|---|
CellArray of Tile
|
The descendant cells in the grid's public identity order. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the target depth is invalid for this cell. |
Examples:
>>> import gometry as gm
>>> cell = gm.tile_cover(gm.Point(-122.4194, 37.7749, crs=4326), zoom=10)[0]
>>> assert cell is not None
>>> len(cell.children())
4
children_count
¶
children_count(zoom: int | None = None) -> int
Number of descendant cells at a finer zoom, counted closed-form without materializing them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zoom
|
int
|
Target zoom; must not be coarser than this cell's.
Defaults to one finer than this cell's zoom;
a maximum-depth cell has no children and returns |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The exact descendant count. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the target depth is coarser than this cell's, or invalid. |
Examples:
>>> import gometry as gm
>>> cell = gm.tile_cover(gm.Point(-122.4194, 37.7749, crs=4326), zoom=10)[0]
>>> assert cell is not None
>>> cell.children_count()
4
parent
¶
parent(zoom: int | None = None) -> Tile
Parent cell at a coarser zoom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zoom
|
int
|
Target zoom; must not be finer than this cell's. Defaults to one coarser than this cell's zoom. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
The ancestor cell. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the target depth is invalid for this cell. |
Examples:
>>> import gometry as gm
>>> cell = gm.tile_cover(gm.Point(-122.4194, 37.7749, crs=4326), zoom=10)[0]
>>> assert cell is not None
>>> parent = cell.parent()
>>> assert parent is not None
>>> str(parent)
'023010203'
Functions¶
tile_bounding_cell
¶
tile_bounding_cell(value: Geometry | GeometryArray[Geometry | None] | Iterable[float]) -> Tile
Return the deepest single tile containing a geometry or lon/lat bounds.
The mercantile bounding_tile: descends the lower-corner tile and accepts
a candidate only after its complete lon/lat rectangle contains the query.
An antimeridian-spanning region is contained by the wrapped z0 world tile;
narrower tiles cannot represent both sides of the seam.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Geometry, GeometryArray, or sequence of float
|
A geometry/array (non-WGS84 frames reproject), or a bare lon/lat
|
required |
Returns:
| Type | Description |
|---|---|
Tile
|
The deepest tile whose rectangle contains the whole bounds. |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If the geometry is empty or coordinates leave the lon/lat domain. |
GeometryError
|
If bare bounds are not ordered min <= max. |
Examples:
>>> import gometry as gm
>>> berlin = gm.box(13.3, 52.4, 13.5, 52.6, crs=4326)
>>> tile = gm.tile_bounding_cell(berlin)
>>> (tile.zoom, tile.x, tile.y)
(5, 17, 10)
tile_cells
¶
Accepted call forms
tile_cells(values: GeometryArray[Point] | Iterable[Point] | (Sequence[Sequence[float]] | ndarray[tuple[int, int], dtype[floating[Any] | signedinteger[Any] | unsignedinteger[Any] | bool_]]) | FloatInput, lat: FloatInput | None = None, *, zoom: int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]] | ndarray[tuple[int], dtype[signedinteger[Any] | unsignedinteger[Any]]] | Iterable[int] | Buffer) -> CellArray[Tile]
tile_cells(values: GeometryArray[Point | None] | Iterable[Point | None], lat: None = None, *, zoom: int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]] | ndarray[tuple[int], dtype[signedinteger[Any] | unsignedinteger[Any]]] | Iterable[int] | Buffer) -> CellArray[Tile | None]
Build tiles from points, coordinate rows, or parallel lon/lat columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
GeometryArray of Point, iterable of Point or None, coordinate matrix, or float
|
Point geometries ( |
required |
lat
|
float or sequence of float
|
WGS84 latitude per row when |
None
|
zoom
|
int or sequence of int
|
Zoom level (0-29; finer at higher values). A scalar broadcasts to every row; an array supplies one zoom per row. Geographic point ownership follows the emitted binary64 tile edges, with west-inclusive/east-exclusive longitude and north-inclusive/south-exclusive latitude ties. |
required |
Returns:
| Type | Description |
|---|---|
CellArray of Tile
|
One tile per input coordinate. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the input is scalar, zoom is invalid, or coordinate columns have different lengths. |
InvalidGeometryError
|
If coordinates are non-finite or leave the lon/lat domain, or a latitude is outside the square Web Mercator tile grid (±85.051129°). |
See Also
Tile : Build a single tile.
Examples:
>>> import gometry as gm
>>> tile = gm.Tile(lon=-105.939, lat=35.687, zoom=9)
>>> (tile.zoom, tile.x, tile.y)
(9, 105, 201)
tile_cover
¶
Accepted call forms
tile_cover(geom: GeometryArray[Geometry] | Iterable[Geometry], zoom: int, *, cell_rule: Literal['center', 'within', 'overlap', 'bbox'] = 'overlap', max_cells: int | None = 1000000) -> Groups[CellArray[Tile]]
Cover a geometry with Web Mercator tiles at a fixed zoom.
The result is a CellArray for scalar input or Groups[CellArray] for
array input, with tiles selected by cell_rule. Keep the source geometry
separately and use the free gm.* predicates for exact geometry
questions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom
|
Geometry, GeometryArray, or iterable of Geometry or None
|
Geometry to cover (WGS84 lon/lat or projected). A scalar returns a
flat cell array; an array or iterable returns one group per input row.
|
required |
zoom
|
int
|
Tile zoom ( |
required |
cell_rule
|
('within', 'center', 'overlap', 'bbox')
|
Which cells to materialize. |
'within'
|
max_cells
|
int or None
|
Hard cap on returned cells and retained result allocation. Discarded
candidates do not consume it; array calls apply it cumulatively across
groups. Pass |
1000000
|
Returns:
| Type | Description |
|---|---|
CellArray or Groups[CellArray]
|
A scalar returns a |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the geometry, zoom, |
InvalidGeometryError
|
If the geometry is empty or any non-polar latitude is outside the square Web Mercator tile grid (±85.05112878 degrees). |
Examples:
>>> import gometry as gm
>>> point = gm.Point(1, 1)
>>> cells = gm.tile_cover(point, zoom=0)
>>> len(cells)
1
tile_difference
¶
tile_difference(left: Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | Iterable[Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | None], right: Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | Iterable[Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | None]) -> CellArray[Tile]
Hierarchy-aware difference of two tile cell sets.
Cells of left partially covered by right split into children
until the remainder is exact; the result is normalized in the grid's
public identity order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
Tile, int, str, or iterable of those with missing values skipped
|
The two cell sets (any mix of cell objects, ids, or tokens). |
required |
right
|
Tile, int, str, or iterable of those with missing values skipped
|
The two cell sets (any mix of cell objects, ids, or tokens). |
required |
Returns:
| Type | Description |
|---|---|
CellArray of Tile
|
|
Raises:
| Type | Description |
|---|---|
ParseError
|
If an id or token is not a valid tile cell. |
Examples:
>>> import gometry as gm
>>> p = gm.Point(-122.4194, 37.7749, crs=4326)
>>> cells = [cell for cell in gm.tile_cover(p, zoom=10) if cell is not None]
>>> len(gm.tile_difference(cells, []))
1
tile_intersection
¶
tile_intersection(left: Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | Iterable[Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | None], right: Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | Iterable[Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | None]) -> CellArray[Tile]
Hierarchy-aware intersection of two tile cell sets.
A cell survives where the two sets overlap; ancestor/descendant overlap keeps the finer cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
Tile, int, str, or iterable of those with missing values skipped
|
The two cell sets (any mix of cell objects, ids, or tokens). |
required |
right
|
Tile, int, str, or iterable of those with missing values skipped
|
The two cell sets (any mix of cell objects, ids, or tokens). |
required |
Returns:
| Type | Description |
|---|---|
CellArray of Tile
|
|
Raises:
| Type | Description |
|---|---|
ParseError
|
If an id or token is not a valid tile cell. |
Examples:
>>> import gometry as gm
>>> p = gm.Point(-122.4194, 37.7749, crs=4326)
>>> cells = [cell for cell in gm.tile_cover(p, zoom=10) if cell is not None]
>>> len(gm.tile_intersection(cells, cells))
1
tile_union
¶
tile_union(left: Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | Iterable[Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | None], right: Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | Iterable[Tile | (int | integer[Any] | ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]]) | str | None]) -> CellArray[Tile]
Hierarchy-aware union of two tile cell sets.
Returns the normalized cell union in the grid's public identity order: contained cells are absorbed by their ancestors and complete sibling groups are merged into parents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
Tile, int, str, or iterable of those with missing values skipped
|
A single cell identity or a collection on either side (any accepted mix of cell objects and identity values for this grid). |
required |
right
|
Tile, int, str, or iterable of those with missing values skipped
|
A single cell identity or a collection on either side (any accepted mix of cell objects and identity values for this grid). |
required |
Returns:
| Type | Description |
|---|---|
CellArray of Tile
|
|
Raises:
| Type | Description |
|---|---|
ParseError
|
If an id or token is not a valid tile cell. |
Examples:
>>> import gometry as gm
>>> p = gm.Point(-122.4194, 37.7749, crs=4326)
>>> cells = [cell for cell in gm.tile_cover(p, zoom=10) if cell is not None]
>>> len(gm.tile_union(cells, cells))
1