Skip to content

geohierarchy.maps.folium.tiles_slow

Vector-tile (XYZ MVT .pbf) generation for a level's geometry.

For a given zoom range, enumerates the XYZ tiles covering a GeoDataFrame's bounds, clips its geometries against the whole tile grid for each zoom in one vectorized pass, encodes each tile's features with mapbox_vector_tile, and writes it to {tiles_dir}/{level}/{z}/{x}/{y}.pbf.

Tiles are written as raw, uncompressed protobuf bytes. It's tempting to gzip them on disk, but Leaflet.VectorGrid fetches a tile with a plain fetch/XHR and only gunzips it if the HTTP response carries a Content-Encoding: gzip header -- something a plain static host (GitHub Pages, python -m http.server, ...) will not add for an arbitrary .pbf extension. A gzip-on-disk tile is therefore fed straight to the protobuf parser as-is and silently fails to decode, rendering nothing.

prep_level_gdf(gdf, id_col, property_cols)

Reproject/trim a level's geometry once, up front, to the small (id_col + property_cols + geometry) frame every zoom's tiling pass actually needs.

Split out of write_level_tiles so HierarchyMap.build() can do this once per level and then fan the (already-small) result out to one parallel job per zoom (see write_level_zoom_tiles) instead of one job per level -- levels differ hugely in tile count (a coarse polygon layer vs. a deep street-edge layer can differ by 2-3 orders of magnitude), so parallelizing only across levels leaves most cores idle while one big level's zooms grind through serially on a single core. Splitting by zoom too keeps every core busy regardless of how lopsided the levels are.

Returns:

Type Description
GeoDataFrame

(work, keep_cols) -- the reprojected/trimmed GeoDataFrame and

List[str]

the property columns kept in it (besides geometry).

Parameters:

Name Type Description Default
gdf GeoDataFrame

The level's geometries.

required
id_col str

Id column kept on every feature.

required
property_cols Iterable[str]

Other columns kept on the features.

required

write_level_zoom_tiles(work, level_name, tiles_dir, z, keep_cols, buffer_frac=0.02)

Tile one level's already-prepped geometry (prep_level_gdf) at a single zoom z. The per-(level, zoom) parallel unit HierarchyMap.build submits to its process pool.

Parameters:

Name Type Description Default
work GeoDataFrame

Geometries prepared by :func:prep_level_gdf.

required
level_name str

Name of the level (tile sub-folder).

required
tiles_dir str

Root folder of the tiles.

required
z int

Zoom level to write.

required
keep_cols List[str]

Columns written on each feature.

required
buffer_frac float

Tile buffer as a fraction of the tile size.

0.02

Returns:

Type Description
List[Path]

Paths of the written tiles.

write_level_tiles(gdf, level_name, tiles_dir, min_zoom, max_zoom, id_col, property_cols, buffer_frac=0.02)

Tile one level's geometry across its assigned zoom range.

Parameters:

Name Type Description Default
gdf GeoDataFrame

Level geometry (EPSG:4326), typically hierarchy.get_level(name).

required
level_name str

Name of the level; also used as the MVT layer name and the top-level directory under tiles_dir.

required
tiles_dir str

Root output directory for all levels' tiles.

required
min_zoom int

Minimum zoom (inclusive) to generate tiles for.

required
max_zoom int

Maximum zoom (inclusive) to generate tiles for.

required
id_col str

Feature id column to keep in tile properties.

required
property_cols Iterable[str]

Additional attribute columns to keep in tile properties (styling/popups read these client-side).

required
buffer_frac float

Tile buffer as a fraction of tile width, used to avoid hairline seams between adjacent tiles for polygons/lines that cross a tile boundary.

0.02

Returns:

Type Description
List[Path]

List of paths to every .pbf file written.