Struct gdal::vector::Geometry

source ·
pub struct Geometry { /* private fields */ }
Expand description

OGR Geometry

Implementations§

source§

impl Geometry

source

pub unsafe fn lazy_feature_geometry() -> Geometry

Create a new Geometry without a C pointer

Safety

This method returns a Geometry without wrapped pointer

source

pub fn has_gdal_ptr(&self) -> bool

source

pub unsafe fn set_c_geometry(&self, c_geometry: OGRGeometryH)

Set the wrapped C pointer

Safety

This method operates on a raw C pointer

source

pub fn empty(wkb_type: Type) -> Result<Geometry>

source

pub fn is_empty(&self) -> bool

source

pub fn bbox(w: f64, s: f64, e: f64, n: f64) -> Result<Geometry>

Create a rectangular geometry from West, South, East and North values.

source

pub unsafe fn c_geometry(&self) -> OGRGeometryH

Returns a C pointer to the wrapped Geometry

Safety

This method returns a raw C pointer

source

pub unsafe fn into_c_geometry(self) -> OGRGeometryH

Returns the C pointer of a Geometry

Safety

This method returns a raw C pointer

source

pub fn set_point(&mut self, i: usize, point: (f64, f64, f64))

source

pub fn set_point_2d(&mut self, i: usize, p: (f64, f64))

source

pub fn add_point(&mut self, p: (f64, f64, f64))

source

pub fn add_point_2d(&mut self, p: (f64, f64))

source

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

source

pub fn get_point_vec(&self) -> Vec<(f64, f64, f64)>

source

pub fn geometry_type(&self) -> Type

Get the geometry type ordinal

See: OGR_G_GetGeometryType

source

pub fn geometry_name(&self) -> String

Get the WKT name for the type of this geometry.

See: OGR_G_GetGeometryName

source

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).

See: OGR_G_GetGeometryCount

source

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

source

pub unsafe fn get_unowned_geometry(&self, n: usize) -> Geometry

Returns the n-th sub-geometry as a non-owned Geometry.

Safety

Don’t keep this object for long.

source

pub fn get_geometry(&self, index: usize) -> GeometryRef<'_>

Get a reference to the geometry at given index

source

pub fn add_geometry(&mut self, sub: Geometry) -> Result<()>

source

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

source

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

source

pub fn envelope(&self) -> Envelope

Computes and returns the axis-aligned 2D bounding envelope for this geometry.

See: OGR_G_GetEnvelope

source

pub fn envelope_3d(&self) -> Envelope3D

Computes and returns the axis aligned 3D bounding envelope for this geometry.

See: OGR_G_GetEnvelope3D

source

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.

See: OGR_G_GetSpatialReference

source

pub fn set_spatial_ref(&mut self, spatial_ref: SpatialRef)

source

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

Methods supporting translation between GDAL Geometry and various text representations.

These include:

source

pub fn from_wkt(wkt: &str) -> Result<Geometry>

Create a geometry by parsing a WKT string.

source

pub fn from_wkb(wkb: &[u8]) -> Result<Geometry>

Creates a geometry by parsing a slice of bytes in WKB (Well-Known Binary) format.

source

pub fn from_geojson(json: &str) -> Result<Geometry>

Create a geometry by parsing a GeoJSON string.

source

pub fn from_gml(json: &str) -> Result<Geometry>

Create a geometry by parsing a GML string.

source

pub fn wkt(&self) -> Result<String>

Serialize the geometry as WKT.

source

pub fn wkb(&self) -> Result<Vec<u8>>

Serializes the geometry to WKB (Well-Known Binary) format.

source

pub fn json(&self) -> Result<String>

Serialize the geometry as GeoJSON.

See: OGR_G_ExportToJson

source§

impl Geometry

source

pub fn to_geo(&self) -> Result<Geometry<f64>>

Create a copy of self as a geo-types geometry.

source§

impl Geometry

Geometric Predicates

These methods provide common spatial relations between two geometries.

source

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

source

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 with VersionInfo::has_geos.

See: OGR_G_Contains

source

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 with VersionInfo::has_geos.

See: OGR_G_Disjoint

source

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 with VersionInfo::has_geos.

See: OGR_G_Touches

source

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 with VersionInfo::has_geos.

See: OGR_G_Crosses

source

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 with VersionInfo::has_geos.

See: OGR_G_Within

source

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 with VersionInfo::has_geos.

See: OGR_G_Overlaps

source§

impl Geometry

Set Operations

These methods provide set operations over two geometries, producing a new geometry.

source

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 with VersionInfo::has_geos.
Returns
  • Some(geometry): a new Geometry representing the computed intersection
  • None: when the geometries do not intersect or result could not be computed

See: OGR_G_Intersection

source

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 with VersionInfo::has_geos.
Returns
  • Some(geometry): a new Geometry representing the computed union
  • None: when the union could not be computed

See: OGR_G_Union

source§

impl Geometry

Geometry Transformations

These methods provide geometric transformations on a Geometry.

source

pub fn transform_inplace(&mut self, htransform: &CoordTransform) -> Result<()>

Apply arbitrary coordinate transformation to geometry, mutating the Geometry in-place.

See: OGR_G_Transform

source

pub fn transform(&self, htransform: &CoordTransform) -> Result<Geometry>

Apply arbitrary coordinate transformation to geometry on a clone of Self.

See: OGR_G_Transform

source

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

source

pub fn transform_to(&self, spatial_ref: &SpatialRef) -> Result<Geometry>

Transforms this geometry’s coordinates into another SpatialRef.

See: OGR_G_TransformTo

source

pub fn convex_hull(&self) -> Result<Geometry>

Compute the convex hull of this geometry.

See: OGR_G_ConvexHull

source

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.

See: OGR_G_DelaunayTriangulation

source

pub fn simplify(&self, tolerance: f64) -> Result<Self>

Compute a simplified geometry.

Arguments
  • tolerance: the distance tolerance for the simplification.

See: OGR_G_Simplify

source

pub fn simplify_preserve_topology(&self, tolerance: f64) -> Result<Self>

Simplify the geometry while preserving topology.

Arguments
  • tolerance: the distance tolerance for the simplification.

See: OGR_G_SimplifyPreserveTopology

source

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

source

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 for METHOD=STRUCTURE.
    • NO (default): Collapses are converted to empty geometries
    • YES: 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()?);

Trait Implementations§

source§

impl Clone for Geometry

source§

fn clone(&self) -> Geometry

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Geometry

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Geometry

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl PartialEq<Geometry> for Geometry

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&Geometry> for Geometry<f64>

§

type Error = GdalError

The type returned in the event of a conversion error.
source§

fn try_from(geo: &Geometry) -> Result<Geometry<f64>, Self::Error>

Performs the conversion.
source§

impl TryFrom<Geometry> for Geometry<f64>

§

type Error = GdalError

The type returned in the event of a conversion error.
source§

fn try_from(value: Geometry) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for Geometry

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.