Skip to content

Crs

Crs

use qgis_render::crs::*;

A coordinate reference system: how coordinates map onto the earth. Every Project, Layer, and render has one, and mismatches between them are resolved by transforming.

Construction

let wgs84 = Crs::from_epsg(4326)?; // WGS 84, geographic
let mercator = Crs::from_epsg(3857)?; // Web Mercator, projected
let utm34 = Crs::from_proj4("+proj=utm +zone=34 +datum=WGS84")?;
let custom = Crs::from_wkt("GEOGCS[\"WGS 84\", ...]")?;

All constructors return Result<Crs, QgisError> and fail with QgisError::CrsError when PROJ cannot resolve the definition.

Properties

MethodReturns
is_geographic()bool — lat/lon units
is_projected()bool — metre units
epsg()Option<u32>
to_wkt()String
to_proj4()String

Transforming coordinates

let transform = CoordTransform::new(&Crs::from_epsg(4326)?, &Crs::from_epsg(3857)?)?;
let (x, y) = transform.transform(14.0, 50.0)?; // lon/lat → metres
let batch = transform.transform_batch(&[(14.0, 50.0), (15.0, 51.0)])?;

Build a CoordTransform once and reuse it — constructing one resolves a PROJ pipeline, which is far more expensive than a single transform call.

Transforming geometries

let reprojected = geom.transform(&wgs84, &mercator)?;

Common choices

EPSGNameTypical use
4326WGS 84Data exchange, GeoJSON, WFS output.
3857Web MercatorXYZ tiles and web maps.
25832–25835ETRS89 / UTMMetric work in Europe.
2180PL-1992National grid for Poland.

See also