Geometry
Geometry
use qgis_render::geometry::*;A vector geometry: point, line, polygon, or a multi- or collection variant of those. Backed by GEOS through QGIS, so predicates and overlays are the same ones QGIS itself uses.
Construction
let geom = Geometry::from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))")?;let geom = Geometry::from_wkb(&bytes)?;let geom = Geometry::from_geojson(json_value)?;Inspection
| Method | Returns |
|---|---|
geometry_type() | GeometryType |
is_empty() | bool |
is_valid() | bool |
area() | f64 |
length() | f64 |
centroid() | Option<Point> |
bounding_box() | Extent |
GeometryType covers Point, LineString, Polygon, MultiPoint,
MultiLineString, MultiPolygon, GeometryCollection, and CircularString.
Serialization
| Method | Returns |
|---|---|
to_wkt() | String |
to_wkb() | Vec<u8> |
to_geojson() | serde_json::Value |
Operations
let buffered = geom.buffer(10.0);let overlap = geom.intersection(&other);let merged = geom.union(&other);let generalised = geom.simplify(0.01); // Douglas-Peucker
let inside = geom.contains(&point);let touching = geom.intersects(&other);let apart = geom.distance(&other);Reprojection
let source = Crs::from_epsg(4326)?;let target = Crs::from_epsg(3857)?;let reprojected = geom.transform(&source, &target)?;See also
geometrymodule —Extent,Point, and helpersCrs— coordinate reference systemsFeature— where geometries usually come from- Working with Layers