Skip to content

tiles

qgis_render::tiles

Pre-rendered XYZ tile pyramids: single tiles on demand, or whole pyramids to a directory, MBTiles, or PMTiles.

use qgis_render::tiles::*;

Single tile

let tile = project.render_tile(
TileCoord { z: 12, x: 2190, y: 1362 },
TileOptions::new(256, 256)
.crs(Crs::from_epsg(3857)?),
)?;
let bytes = tile.png_bytes();
TileOptions methodDefaultDescription
.crs(Crs)EPSG:3857Tile CRS. XYZ pyramids are normally Web Mercator.
.format(TileFormat)PngPng, Jpeg, or WebP.
.dpi(u32)96Raise for retina tiles.

Tile plans

A TilePlan describes the pyramid: which zoom levels, which area, how big the tiles are.

let plan = TilePlan::new()
.zoom_range(10..=14)
.bounds(Extent::new(14.0, 50.0, 15.0, 51.0))
.tile_size(256)
.crs(Crs::from_epsg(3857)?);
println!("{} tiles", plan.tile_count());

Rendering a plan

// Loose {z}/{x}/{y}.png files
plan.render_to_dir(&project, "./tiles/", RenderOptions::new()
.parallel(8)
.progress(|done, total| println!("{done}/{total}"))
)?;
// MBTiles
plan.render_to_mbtiles(&project, "output.mbtiles", RenderOptions::new()
.parallel(8)
.format(TileFormat::Png)
)?;
// PMTiles
plan.render_to_pmtiles(&project, "output.pmtiles", RenderOptions::new()
.parallel(8)
.format(TileFormat::WebP)
)?;
RenderOptions methodDefaultDescription
.parallel(usize)CPU countWorker threads; each owns a QGIS instance.
.format(TileFormat)PngOutput encoding.
.progress(f)noneCalled after each tile with (done, total).

Choosing an output

TargetGood for
DirectoryDebugging, serving through any static file server or CDN.
MBTilesSingle portable file, well supported by tooling.
PMTilesSingle file served over HTTP range requests, no tile server needed.

See also