Skip to content

geohierarchy.maps.folium.pmtiles_to_xyz

Convert PMTiles archives to XYZ .pbf directory structure.

This module provides utilities to extract XYZ tile directories from PMTiles archives, allowing them to be used with folium + Leaflet.VectorGrid which expects the standard XYZ directory structure.

PMTiles format: https://github.com/protomaps/PMTiles XYZ format expected by geohierarchy: {tiles_dir}/{level_name}/{z}/{x}/{y}.pbf

extract_xyz_from_pmtiles(pmtiles_path, xyz_dir, layer_name=None, min_zoom=None, max_zoom=None, overwrite=True, quiet=False)

Extract XYZ .pbf tile directory from a PMTiles archive.

This reads a PMTiles file and writes each tile to the standard XYZ directory structure that Leaflet.VectorGrid expects: {xyz_dir}/{layer_name}/{z}/{x}/{y}.pbf

Parameters:

Name Type Description Default
pmtiles_path Union[str, Path]

Path to the input .pmtiles file

required
xyz_dir Union[str, Path]

Output directory for XYZ tiles (will be created if needed)

required
layer_name Optional[str]

Layer name to use in the directory structure. If None, uses the PMTiles filename stem.

None
min_zoom Optional[int]

Minimum zoom to extract (None = all zooms in PMTiles). Currently not implemented - extracts all zooms.

None
max_zoom Optional[int]

Maximum zoom to extract (None = all zooms in PMTiles). Currently not implemented - extracts all zooms.

None
overwrite bool

If True, overwrite existing XYZ directory

True
quiet bool

Suppress progress messages

False

Returns:

Type Description
Path

Path to the output xyz_dir/layer_name

Example

extract_xyz_from_pmtiles( "census.pmtiles", "tiles", layer_name="census", )

Creates: tiles/census/0/0/0.pbf, tiles/census/1/0/0.pbf, etc.

extract_xyz_from_pmtiles_bulk(pmtiles_paths, xyz_dir, overwrite=True, quiet=False)

Extract XYZ directories from multiple PMTiles files.

Useful for extracting all layers at once.

Parameters:

Name Type Description Default
pmtiles_paths dict[str, Union[str, Path]]

Dictionary mapping layer_name -> PMTiles file path

required
xyz_dir Union[str, Path]

Root output directory

required
overwrite bool

Overwrite existing directories

True
quiet bool

Suppress progress messages

False

Returns:

Type Description
dict[str, Path]

Dictionary mapping layer_name -> extracted XYZ directory path