pub struct Geometry { /* private fields */ }
Expand description
OGR Geometry
Implementations§
source§impl Geometry
impl Geometry
sourcepub unsafe fn lazy_feature_geometry() -> Geometry
pub unsafe fn lazy_feature_geometry() -> Geometry
Create a new Geometry without a C pointer
Safety
This method returns a Geometry without wrapped pointer
pub fn has_gdal_ptr(&self) -> bool
sourcepub unsafe fn set_c_geometry(&self, c_geometry: OGRGeometryH)
pub unsafe fn set_c_geometry(&self, c_geometry: OGRGeometryH)
pub fn empty(wkb_type: Type) -> Result<Geometry>
pub fn is_empty(&self) -> bool
sourcepub fn bbox(w: f64, s: f64, e: f64, n: f64) -> Result<Geometry>
pub fn bbox(w: f64, s: f64, e: f64, n: f64) -> Result<Geometry>
Create a rectangular geometry from West, South, East and North values.
sourcepub unsafe fn c_geometry(&self) -> OGRGeometryH
pub unsafe fn c_geometry(&self) -> OGRGeometryH
sourcepub unsafe fn into_c_geometry(self) -> OGRGeometryH
pub unsafe fn into_c_geometry(self) -> OGRGeometryH
pub fn set_point(&mut self, i: usize, point: (f64, f64, f64))
pub fn set_point_2d(&mut self, i: usize, p: (f64, f64))
pub fn add_point(&mut self, p: (f64, f64, f64))
pub fn add_point_2d(&mut self, p: (f64, f64))
sourcepub fn get_point(&self, index: i32) -> (f64, f64, f64)
pub fn get_point(&self, index: i32) -> (f64, f64, f64)
Get point coordinates from a line string or a point geometry.
index
is the line string vertex index, from 0 to point_count()-1
, or 0
when a point.
See: OGR_G_GetPoint
pub fn get_point_vec(&self) -> Vec<(f64, f64, f64)>
sourcepub fn geometry_type(&self) -> Type
pub fn geometry_type(&self) -> Type
Get the geometry type ordinal
sourcepub fn geometry_name(&self) -> String
pub fn geometry_name(&self) -> String
Get the WKT name for the type of this geometry.
sourcepub fn geometry_count(&self) -> usize
pub fn geometry_count(&self) -> usize
Get the number of elements in a geometry, or number of geometries in container.
Only geometries of type wkbPolygon
, wkbMultiPoint
, wkbMultiLineString
, wkbMultiPolygon
or wkbGeometryCollection
may return a non-zero value. Other geometry types will return 0.
For a polygon, the returned number is the number of rings (exterior ring + interior rings).
sourcepub fn point_count(&self) -> usize
pub fn point_count(&self) -> usize
Get the number of points from a Point or a LineString/LinearRing geometry.
Only wkbPoint
or wkbLineString
may return a non-zero value. Other geometry types will return 0.
See: OGR_G_GetPointCount
sourcepub unsafe fn get_unowned_geometry(&self, n: usize) -> Geometry
pub unsafe fn get_unowned_geometry(&self, n: usize) -> Geometry
sourcepub fn get_geometry(&self, index: usize) -> GeometryRef<'_>
pub fn get_geometry(&self, index: usize) -> GeometryRef<'_>
Get a reference to the geometry at given index
pub fn add_geometry(&mut self, sub: Geometry) -> Result<()>
sourcepub fn length(&self) -> f64
pub fn length(&self) -> f64
Compute geometry area in units of the spatial reference system in use.
Supported for Curve
(including LineString
and CircularString
) and MultiCurve
.
Returns zero for all other geometry types.
See: OGR_G_Length
sourcepub fn area(&self) -> f64
pub fn area(&self) -> f64
Compute geometry area in square units of the spatial reference system in use.
Supported for LinearRing
, Polygon
and MultiPolygon
.
Returns zero for all other geometry types.
See: OGR_G_Area
sourcepub fn envelope(&self) -> Envelope
pub fn envelope(&self) -> Envelope
Computes and returns the axis-aligned 2D bounding envelope for this geometry.
See: OGR_G_GetEnvelope
sourcepub fn envelope_3d(&self) -> Envelope3D
pub fn envelope_3d(&self) -> Envelope3D
Computes and returns the axis aligned 3D bounding envelope for this geometry.
See: OGR_G_GetEnvelope3D
sourcepub fn spatial_ref(&self) -> Option<SpatialRef>
pub fn spatial_ref(&self) -> Option<SpatialRef>
Get the spatial reference system for this geometry.
Returns Some(SpatialRef)
, or None
if one isn’t defined.
pub fn set_spatial_ref(&mut self, spatial_ref: SpatialRef)
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Test if the geometry is valid.
Notes
This function requires the GEOS library.
If OGR is built without the GEOS library, this function will always return false
.
Check with VersionInfo::has_geos
.
See: Self::make_valid
See: OGR_G_IsValid
source§impl Geometry
impl Geometry
Methods supporting translation between GDAL Geometry
and various text representations.
These include:
sourcepub fn from_wkb(wkb: &[u8]) -> Result<Geometry>
pub fn from_wkb(wkb: &[u8]) -> Result<Geometry>
Creates a geometry by parsing a slice of bytes in WKB (Well-Known Binary) format.
sourcepub fn from_geojson(json: &str) -> Result<Geometry>
pub fn from_geojson(json: &str) -> Result<Geometry>
Create a geometry by parsing a GeoJSON string.
sourcepub fn wkb(&self) -> Result<Vec<u8>>
pub fn wkb(&self) -> Result<Vec<u8>>
Serializes the geometry to WKB (Well-Known Binary) format.
sourcepub fn json(&self) -> Result<String>
pub fn json(&self) -> Result<String>
Serialize the geometry as GeoJSON.
See: OGR_G_ExportToJson
source§impl Geometry
impl Geometry
Geometric Predicates
These methods provide common spatial relations between two geometries.
sourcepub fn intersects(&self, other: &Self) -> bool
pub fn intersects(&self, other: &Self) -> bool
Tests if two geometries intersect;
self
and other
have at least one point in common.
If GEOS is enabled, then this is done in rigorous fashion, otherwise true
is returned
if the envelopes (bounding boxes) of the two geometries overlap. Check with VersionInfo::has_geos
.
See: OGR_G_Intersects
sourcepub fn contains(&self, other: &Self) -> bool
pub fn contains(&self, other: &Self) -> bool
Tests if this geometry contains the other geometry;
other
lies in self
, and the interiors intersect.
Notes
- Geometry validity is not checked, and invalid geometry will generate unpredictable results.
Use
Geometry::is_valid
if validity might be in question. - If GEOS is not enabled, this function will always return
false
. Check withVersionInfo::has_geos
.
See: OGR_G_Contains
sourcepub fn disjoint(&self, other: &Self) -> bool
pub fn disjoint(&self, other: &Self) -> bool
Tests if this geometry and the other geometry are disjoint;
self
and other
form a set of disconnected geometries.
Notes
- Geometry validity is not checked, and invalid geometry will generate unpredictable results.
Use
Geometry::is_valid
if validity might be in question. - If GEOS is not enabled, this function will always return
false
. Check withVersionInfo::has_geos
.
See: OGR_G_Disjoint
sourcepub fn touches(&self, other: &Self) -> bool
pub fn touches(&self, other: &Self) -> bool
Tests if this geometry and the other geometry are touching;
self
and other
have at least one point in common, but their interiors do not intersect.
Notes
- Geometry validity is not checked, and invalid geometry will generate unpredictable results.
Use
Geometry::is_valid
if validity might be in question. - If GEOS is not enabled, this function will always return
false
. Check withVersionInfo::has_geos
.
See: OGR_G_Touches
sourcepub fn crosses(&self, other: &Self) -> bool
pub fn crosses(&self, other: &Self) -> bool
Tests if this geometry and the other geometry are crossing;
self
and other
have some but not all interior points in common, and the dimension of
the intersection is less than that of at least one of them.
Notes
- Geometry validity is not checked, and invalid geometry will generate unpredictable results.
Use
Geometry::is_valid
if validity might be in question. - If GEOS is not enabled, this function will always return
false
. Check withVersionInfo::has_geos
.
See: OGR_G_Crosses
sourcepub fn within(&self, other: &Self) -> bool
pub fn within(&self, other: &Self) -> bool
Tests if this geometry is within the other;
self
lies fully in the interior of other
.
Notes
- Geometry validity is not checked, and invalid geometry will generate unpredictable results.
Use
Geometry::is_valid
if validity might be in question. - If GEOS is not enabled, this function will always return
false
. Check withVersionInfo::has_geos
.
See: OGR_G_Within
sourcepub fn overlaps(&self, other: &Self) -> bool
pub fn overlaps(&self, other: &Self) -> bool
Tests if this geometry and the other overlap;
self
and other
they have some but not all points in common,
they have the same dimension,
and the intersection of the interiors has the same dimension as the geometries.
Notes
- Geometry validity is not checked, and invalid geometry will generate unpredictable results.
Use
Geometry::is_valid
if validity might be in question. - If GEOS is not enabled, this function will always return
false
. Check withVersionInfo::has_geos
.
See: OGR_G_Overlaps
source§impl Geometry
impl Geometry
Set Operations
These methods provide set operations over two geometries, producing a new geometry.
sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
Computes the geometric intersection of self
and other
.
Generates a new geometry which is the region of intersection of the two geometries operated on.
Notes
- If you only need to determine if two geometries intersect and don’t require
the resultant region, use
Geometry::intersects
. - Geometry validity is not checked, and invalid geometry will generate unpredictable results.
Use
Geometry::is_valid
if validity might be in question. - If GEOS is not enabled, this function will always return
None
. You may check for GEOS support withVersionInfo::has_geos
.
Returns
Some(geometry)
: a newGeometry
representing the computed intersectionNone
: when the geometries do not intersect or result could not be computed
See: OGR_G_Intersection
sourcepub fn union(&self, other: &Self) -> Option<Self>
pub fn union(&self, other: &Self) -> Option<Self>
Computes the geometric union of self
and other
.
Generates a new geometry which is the union of the two geometries operated on.
Notes
- Geometry validity is not checked, and invalid geometry will generate unpredictable results.
Use
Geometry::is_valid
if validity might be in question. - If GEOS is not enabled, this function will always return
None
. You may check for GEOS support withVersionInfo::has_geos
.
Returns
Some(geometry)
: a newGeometry
representing the computed unionNone
: when the union could not be computed
See: OGR_G_Union
source§impl Geometry
impl Geometry
Geometry Transformations
These methods provide geometric transformations on a Geometry
.
sourcepub fn transform_inplace(&mut self, htransform: &CoordTransform) -> Result<()>
pub fn transform_inplace(&mut self, htransform: &CoordTransform) -> Result<()>
Apply arbitrary coordinate transformation to geometry, mutating the Geometry
in-place.
See: OGR_G_Transform
sourcepub fn transform(&self, htransform: &CoordTransform) -> Result<Geometry>
pub fn transform(&self, htransform: &CoordTransform) -> Result<Geometry>
Apply arbitrary coordinate transformation to geometry on a clone of Self
.
See: OGR_G_Transform
sourcepub fn transform_to_inplace(&mut self, spatial_ref: &SpatialRef) -> Result<()>
pub fn transform_to_inplace(&mut self, spatial_ref: &SpatialRef) -> Result<()>
Transforms this geometry’s coordinates into another SpatialRef
, mutating the Geometry
in-place.
See: OGR_G_TransformTo
sourcepub fn transform_to(&self, spatial_ref: &SpatialRef) -> Result<Geometry>
pub fn transform_to(&self, spatial_ref: &SpatialRef) -> Result<Geometry>
Transforms this geometry’s coordinates into another SpatialRef
.
See: OGR_G_TransformTo
sourcepub fn convex_hull(&self) -> Result<Geometry>
pub fn convex_hull(&self) -> Result<Geometry>
Compute the convex hull of this geometry.
See: OGR_G_ConvexHull
sourcepub fn delaunay_triangulation(&self, tolerance: Option<f64>) -> Result<Self>
pub fn delaunay_triangulation(&self, tolerance: Option<f64>) -> Result<Self>
Return a Delaunay triangulation of the vertices of the geometry.
Arguments
tolerance
: optional snapping tolerance to use for improved robustness
Notes
This function requires GEOS library, v3.4 or above.
If OGR is built without the GEOS library, this function will always fail.
Check with VersionInfo::has_geos
.
sourcepub fn simplify(&self, tolerance: f64) -> Result<Self>
pub fn simplify(&self, tolerance: f64) -> Result<Self>
Compute a simplified geometry.
Arguments
tolerance
: the distance tolerance for the simplification.
See: OGR_G_Simplify
sourcepub fn simplify_preserve_topology(&self, tolerance: f64) -> Result<Self>
pub fn simplify_preserve_topology(&self, tolerance: f64) -> Result<Self>
Simplify the geometry while preserving topology.
Arguments
tolerance
: the distance tolerance for the simplification.
sourcepub fn buffer(&self, distance: f64, n_quad_segs: u32) -> Result<Self>
pub fn buffer(&self, distance: f64, n_quad_segs: u32) -> Result<Self>
Compute buffer of geometry
Arguments
distance
: the buffer distance to be applied. Should be expressed in the same unit as the coordinates of the geometry.n_quad_segs
specifies the number of segments used to approximate a 90 degree (quadrant) of curvature.
See: OGR_G_Buffer
sourcepub fn make_valid(&self, opts: &CslStringList) -> Result<Geometry>
pub fn make_valid(&self, opts: &CslStringList) -> Result<Geometry>
Attempts to make an invalid geometry valid without losing vertices.
Already-valid geometries are cloned without further intervention.
Extended options are available via CslStringList
if GDAL is built with GEOS >= 3.8.
They are defined as follows:
METHOD=LINEWORK
: Combines all rings into a set of node-ed lines and then extracts valid polygons from that “linework”.METHOD=STRUCTURE
: First makes all rings valid, then merges shells and subtracts holes from shells to generate valid result. Assumes holes and shells are correctly categorized.KEEP_COLLAPSED=YES/NO
. Only forMETHOD=STRUCTURE
.NO
(default): Collapses are converted to empty geometriesYES
: collapses are converted to a valid geometry of lower dimension
When GEOS < 3.8, this method will return Ok(self.clone())
if it is valid, or Err
if not.
See: OGR_G_MakeValidEx
Example
use gdal::cpl::CslStringList;
use gdal::vector::Geometry;
let src = Geometry::from_wkt("POLYGON ((0 0, 10 10, 0 10, 10 0, 0 0))")?;
let dst = src.make_valid(&CslStringList::new())?;
assert_eq!("MULTIPOLYGON (((10 0, 0 0, 5 5, 10 0)),((10 10, 5 5, 0 10, 10 10)))", dst.wkt()?);