Skip to content

render

qgis_render::render

The rendering entry points. Everything here turns a Project plus a MapSettings into pixels.

use qgis_render::render::*;

Functions and methods

Rendering is driven from Project:

MethodReturnsDescription
render(&settings)Result<Image, QgisError>Render to an in-memory image.
render_to_image(RenderSettings)Result<Image, QgisError>Shorthand for a simple render.
render_to_file(&settings, path)Result<(), QgisError>Render and encode to a file.
render_to_writer(&settings, &mut W)Result<(), QgisError>Render into any std::io::Write.
render_to_tile(&settings, z, x, y)Result<Image, QgisError>Render one XYZ tile.
render_async(&settings)Future<Result<Image>>Render on the blocking pool; await it from async code.

MapSettings

Full control over a single render.

let settings = MapSettings::new(2048, 2048)
.extent(Extent::new(14.0, 50.0, 15.0, 51.0))
.crs(Crs::from_epsg(4326)?)
.dpi(150)
.background(Color::rgba(240, 240, 240, 255))
.layers(&["buildings", "roads", "labels"])
.layer_filter("buildings", Filter::gt("height", 10))
.antialiasing(true);
let image = project.render(&settings)?;
Builder methodDefaultDescription
.extent(Extent)project extentArea to render.
.crs(Crs)project CRSOutput CRS.
.dpi(u32)96Resolution, used for labels and symbol scaling.
.background(Color)transparentBackground fill.
.layers(&[&str])all visible layersRestrict the render to these layers.
.layer_filter(&str, Filter)—Override a layer’s filter for this render only.
.antialiasing(bool)trueEdge smoothing.

For the common case, RenderSettings is the lighter-weight builder.

Image

MethodReturnsDescription
save(path)Result<(), QgisError>Encode by extension: .png, .jpg, .webp.
to_png_bytes()Result<Vec<u8>, QgisError>PNG in memory.
width() / height()u32Pixel dimensions.
pixel(x, y)ColorSample one pixel.

Examples

// Quick render
let image = project.render_to_image(RenderSettings::new(1024, 768))?;
image.save("map.png")?;
// Stream into an HTTP response
project.render_to_writer(&settings, &mut response.body)?;
// From async code (for example inside an axum handler)
let image = project.render_async(&settings).await?;

See also