Expand description
The geo crate provides planar geospatial geometries and algorithms.
§Overview
- Full DE-9IM support and topological relationship calculations such as containment and intersection
- Affine operations on geometries (scale, rotate, skew, translate)
- Boolean operations on geometries (clip, union, difference, intersection, xor)
- Buffer / offset operations on geometries
- Euclidean, as well as spherical, haversine and other non-planar length and distance calculations
- Support for projecting and converting between coordinate reference systems using PROJ
- IO using the geojsonandgeozerocrates.
For a full listing of available geometry types, functionality and features, see below:
§Types
- Coord: A two-dimensional coordinate. All geometry types are composed of- Coords, though- Coorditself is not a- Geometrytype
- Point: A single point represented by one- Coord
- MultiPoint: A collection of- Points
- Line: A line segment represented by two- Coords
- LineString: A series of contiguous line segments represented by two or more- Coords
- MultiLineString: A collection of- LineStrings
- Polygon: A bounded area represented by one- LineStringexterior ring, and zero or more- LineStringinterior rings
- MultiPolygon: A collection of- Polygons
- Rect: An axis-aligned bounded rectangle represented by minimum and maximum- Coords
- Triangle: A bounded area represented by three- Coordvertices
- GeometryCollection: A collection of- Geometrys
- Geometry: An enumeration of all geometry types, excluding- Coord
The preceding types are reexported from the geo-types crate. Consider using that crate
if you only need access to these types and no other geo functionality.
§Semantics
The geospatial types provided here aim to adhere to the OpenGIS Simple feature access standards. Thus, the types here are inter-operable with other implementations of the standards: JTS, GEOS, etc.
§Algorithms
§Measures
Algorithms for measures along a line, and how a line is measured.
§Metric Spaces
- Euclidean: The Euclidean plane measures distance with the pythagorean formula. Not suitable for lon/lat geometries.
- Haversine: The Haversine Formula measures distance on a sphere. Only suitable for lon/lat geometries.
- Geodesic: Geodesic methods based on Karney (2013) more accurately reflect the shape of the Earth, but are slower than Haversine. Only suitable for lon/lat geometries.
- Rhumb: Rhumb line (a.k.a. loxodrome) measures can be useful for navigation applications where maintaining a constant bearing or direction is important. Only suitable for lon/lat geometries.
§Operations on Metric Spaces
- 
Distance: Calculate the minimum distance between two geometries.
- 
Length: Calculate the length of aLine,LineString, orMultiLineString.
- 
Bearing: Calculate the bearing between two points.
- 
Destination: Calculate the destination point from an origin point, given a bearing and a distance.
- 
InterpolateLine: Interpolate aPointalong aLineorLineString.
- 
InterpolatePoint: Interpolate points along a line.
- 
Densify: Insert points into a geometry so there is never more thanmax_segment_lengthbetween points.
§Misc measures
- HausdorffDistance: Calculate “the maximum of the distances from a point in any of the sets to the nearest point in the other set.” (Rote, 1991)
- VincentyDistance: Calculate the minimum geodesic distance between geometries using Vincenty’s formula
- VincentyLength: Calculate the geodesic length of a geometry using Vincenty’s formula
- FrechetDistance: Calculate the similarity between- LineStrings using the Fréchet distance
§Area
- Area: Calculate the planar area of a geometry
- ChamberlainDuquetteArea: Calculate the geodesic area of a geometry on a sphere using the algorithm presented in Some Algorithms for Polygons on a Sphere by Chamberlain and Duquette (2007)
- GeodesicArea: Calculate the geodesic area and perimeter of a geometry on an ellipsoid using the algorithm presented in Algorithms for geodesics by Charles Karney (2013)
§Boolean Operations
- BooleanOps: Combine or split (Multi)Polygons using intersection, union, xor, or difference operations
- unary_union: Efficient union of many- Polygonor- MultiPolygons
§Outlier Detection
- OutlierDetection: Detect outliers in a group of points using LOF
§Simplification
- Simplify: Simplify a geometry using the Ramer–Douglas–Peucker algorithm
- SimplifyIdx: Calculate a simplified geometry using the Ramer–Douglas–Peucker algorithm, returning coordinate indices
- SimplifyVw: Simplify a geometry using the Visvalingam-Whyatt algorithm
- SimplifyVwPreserve: Simplify a geometry using a topology-preserving variant of the Visvalingam-Whyatt algorithm
- SimplifyVwIdx: Calculate a simplified geometry using the Visvalingam-Whyatt algorithm, returning coordinate indices
§Query
- ClosestPoint: Find the point on a geometry closest to a given point
- HaversineClosestPoint: Find the point on a geometry closest to a given point on a sphere using spherical coordinates and lines being great arcs
- IsConvex: Calculate the convexity of a- LineString
- LineLocatePoint: Calculate the fraction of a line’s total length representing the location of the closest point on the line to the given point
- InteriorPoint: Calculates a representative point inside a- Geometry
§Topology
- Contains: Calculate if a geometry contains another geometry
- CoordinatePosition: Calculate the position of a coordinate relative to a geometry
- HasDimensions: Determine the dimensions of a geometry
- Intersects: Calculate if a geometry intersects another geometry
- line_intersection: Calculates the intersection, if any, between two lines
- Intersections: Find all line segment intersections using an efficient sweep line algorithm (Bentley-Ottmann)
- Relate: Topologically relate two geometries based on DE-9IM semantics
- Within: Calculate if a geometry lies completely within another geometry
§Triangulation
- TriangulateEarcut: Triangulate polygons using the earcut algorithm. Requires the- earcutrfeature, which is enabled by default
- TriangulateDelaunay: Produce constrained or unconstrained Delaunay triangulations of polygons. Requires the- spadefeature, which is enabled by default
§Winding
- Orient: Apply a specified winding- Directionto a- Polygon’s interior and exterior rings
- Winding: Calculate and manipulate the- WindingOrderof a- LineString
§Iteration
- CoordsIter: Iterate over the coordinates of a geometry
- MapCoords: Map a function over all the coordinates in a geometry, returning a new geometry
- MapCoordsInPlace: Map a function over all the coordinates in a geometry in-place
- LinesIter: Iterate over lines of a geometry
§Boundary
- BoundingRect: Calculate the axis-aligned bounding rectangle of a geometry
- MinimumRotatedRect: Calculate the minimum bounding box of a geometry
- ConcaveHull: Calculate the concave hull of a geometry
- ConvexHull: Calculate the convex hull of a geometry
- Extremes: Calculate the extreme coordinates and indices of a geometry
§Affine transformations
- Rotate: Rotate a geometry around its centroid
- Scale: Scale a geometry up or down by a factor
- Skew: Skew a geometry by shearing angles along the- xand- ydimension
- Translate: Translate a geometry along its axis
- AffineOps: generalised composable affine operations
§Conversion
- Convert: Convert (infallibly) the numeric type of a geometry’s coordinate value
- TryConvert: Convert (fallibly) the numeric type of a geometry’s coordinate value
- ToDegrees: Radians to degrees coordinate transforms for a given geometry
- ToRadians: Degrees to radians coordinate transforms for a given geometry
§Miscellaneous
- Buffer: Create a new geometry whose boundary is offset the specified distance from the input.
- Centroid: Calculate the centroid of a geometry
- ChaikinSmoothing: Smoothen- LineString,- Polygon,- MultiLineStringand- MultiPolygonusing Chaikin’s algorithm
- [proj]: Project geometries with theprojcrate (requires theuse-projfeature)
- LineStringSegmentize: Segment a LineString into- nsegments
- LineStringSegmentizeHaversine: Segment a LineString using Haversine distance
- [Transform]: Transform a geometry using Proj
- RemoveRepeatedPoints: Remove repeated points from a geometry
- Validation: Checks if the geometry is well formed. Some algorithms may not work correctly with invalid geometries
§Spatial Indexing
geo geometries (Point, Line, LineString, Polygon, MultiPolygon) can be used with the rstar
R*-tree crate for fast distance and nearest-neighbour queries. Multi- geometries can be added to the tree by iterating over
their members and adding them. Note in particular the availability of the bulk_load
method and GeomWithData struct.
§Features
The following optional Cargo features are available:
- earcutr:- Enables the earcutrcrate, which provides triangulation of polygons using the earcut algorithm
- ☑ Enabled by default
 
- Enables the 
- proj-network:- Enables network grid support for the projcrate
- After enabling this feature, further configuration is required to use the network grid.
- ☐ Disabled by default
 
- Enables network grid support for the 
- use-proj:- Enables coordinate conversion and transformation of Pointgeometries using theprojcrate
- ☐ Disabled by default
 
- Enables coordinate conversion and transformation of 
- use-serde:- Allows geometry types to be serialized and deserialized with Serde
- ☐ Disabled by default
 
- multithreading:- Enables multithreading support (via Rayon), and activates the multithreadingflag ingeo-types, enabling multi-threaded iteration overMulti*geometries
- ☑ Enabled by default
 
- Enables multithreading support (via Rayon), and activates the 
§Ecosystem
There’s a wide variety of geo-compatible crates in the ecosystem that offer functionality not
included in the geo crate, including:
- Reading and writing file formats (e.g. GeoJSON, WKT, shapefile)
- Latitude and longitude parsing
- Label placement
- Geocoding
- and much more…
Re-exports§
- pub use crate::algorithm::sweep::Intersections;
- pub use crate::relate::PreparedGeometry;
- pub use crate::algorithm::*;
- pub use geometry::*;
Modules§
- algorithm
- This module includes all the functions of geometric calculations
- geometry
- This module makes all geometry types available
- prelude
- A prelude which re-exports the traits for manipulating objects in this
crate. Typically imported with use geo::prelude::*.
Macros§
- coord
- Creates a Coordfrom the given scalars.
- geometry_delegate_ impl 
- Implements the common pattern where a Geometry enum simply delegates its trait impl to it’s inner type.
- line_string 
- Creates a LineStringcontaining the given coordinates.
- point
- Creates a Pointfrom the given coordinates.
- polygon
- Creates a Polygoncontaining the given coordinates.
- wkt
- Creates a crate::geometryfrom a WKT literal.
Enums§
- Closest
- The result of trying to find the closest spot on an object to a point.
Traits§
- CoordFloat 
- For algorithms which can only use floating point Points/Coords, like area or length calculations
- CoordNum 
- For algorithms which can use both integer and floating point Points/Coords
- GeoFloat
- A common numeric trait used for geo algorithms
- GeoNum
- A trait for methods which work for both integers and floating point