Class Measures
- Namespace
- SpatialNET
- Assembly
- SpatialNET.Extensions.dll
Measures: area, length, envelope, centroid and distance (ADR 0012).
public static class MeasuresInheritance
Inherited Members
Remarks
Measures assume valid input (ADR 0003); for invalid input the result is deterministic but not guaranteed. Empty or invalid geometries never throw.
Methods
Area(IPolygon2D)
The area by the even-odd rule: shells minus holes, islands in holes positive again.
public static double Area(this IPolygon2D polygon)Parameters
polygonIPolygon2D-
The polygon.
Returns
Exceptions
- ArgumentNullException
-
polygonisnull.
Area(IGeometry2D)
The area; 0 for points, multipoints and polylines.
public static double Area(this IGeometry2D geometry)Parameters
geometryIGeometry2D-
The geometry.
Returns
Exceptions
- ArgumentNullException
-
geometryisnull. - NotSupportedException
-
geometryis not a known geometry kind.
Centroid(IGeometry2D)
The centroid as a value, without Z; null for an empty geometry.
Areas are area-weighted, lines length-weighted, points averaged; if a geometry has
no area or length, the computation falls back to the next lower dimension (as in JTS).
public static Coordinate? Centroid(this IGeometry2D geometry)Parameters
geometryIGeometry2D-
The geometry.
Returns
Exceptions
- ArgumentNullException
-
geometryisnull. - NotSupportedException
-
geometryis not a known geometry kind.
Distance(IGeometry2D, IGeometry2D)
The smallest distance between two geometries; 0 if they intersect or one lies in the area of the other. System.Double.NaN if either is empty (deliberate deviation from NTS, ADR 0012).
public static double Distance(this IGeometry2D a, IGeometry2D b)Parameters
aIGeometry2D-
The first geometry.
bIGeometry2D-
The second geometry.
Returns
Exceptions
- ArgumentNullException
-
aorbisnull. - NotSupportedException
-
A geometry is not a known geometry kind.
Envelope(IGeometry2D)
The envelope; SpatialNET.Envelope2D.Empty for an empty geometry.
public static Envelope2D Envelope(this IGeometry2D geometry)Parameters
geometryIGeometry2D-
The geometry.
Returns
Exceptions
- ArgumentNullException
-
geometryisnull. - NotSupportedException
-
geometryis not a known geometry kind.
HausdorffDistance(IGeometry2D, IGeometry2D, double)
The discrete Hausdorff distance (ADR 0025): the larger of the two directed distances, where the directed distance from A to
B is the greatest distance from a sample point of A to the line work of B. The sample points are the vertices of A
and, with densifyFraction below 1, extra points that divide every segment into equal pieces. The
value is exact for the samples and a lower bound of the true Hausdorff distance; a smaller fraction approaches it.
A polygon counts by its rings (the line work), not by its area, as in JTS.
public static double HausdorffDistance(this IGeometry2D a, IGeometry2D b, double densifyFraction = 1)Parameters
aIGeometry2D-
The first geometry.
bIGeometry2D-
The second geometry.
densifyFractiondouble-
In (0, 1]: every segment is divided into
round(1 / densifyFraction)pieces; 1 (default) uses the vertices only.
Returns
- double
-
The distance, or System.Double.NaN if one geometry is empty.
Exceptions
- ArgumentNullException
-
aorbisnull. - ArgumentOutOfRangeException
-
densifyFractionis not in (0, 1], or so small that the number of samples would be unreasonably large. - NotSupportedException
-
A geometry is not a known geometry kind.
IsWithinDistance(IGeometry2D, IGeometry2D, double)
Whether the distance between two geometries is at most distance (0 = they touch or
overlap). Faster than comparing SpatialNET.Measures.Distance(SpatialNET.IGeometry2D,SpatialNET.IGeometry2D) because it stops at the first
pair of segments within the distance (ADR 0019).
public static bool IsWithinDistance(this IGeometry2D a, IGeometry2D b, double distance)Parameters
aIGeometry2D-
The first geometry.
bIGeometry2D-
The second geometry.
distancedouble-
The distance; finite and not negative.
Returns
- bool
-
falseif either geometry is empty.
Exceptions
- ArgumentNullException
-
aorbisnull. - ArgumentOutOfRangeException
-
distanceis negative,NaNor infinite. - NotSupportedException
-
A geometry is not a known geometry kind.
Length(IPolyline2D)
The length of all paths.
public static double Length(this IPolyline2D polyline)Parameters
polylineIPolyline2D-
The polyline.
Returns
Exceptions
- ArgumentNullException
-
polylineisnull.
Length(IPolygon2D)
The perimeter: the length of all rings, each closed.
public static double Length(this IPolygon2D polygon)Parameters
polygonIPolygon2D-
The polygon.
Returns
Exceptions
- ArgumentNullException
-
polygonisnull.
Length(IGeometry2D)
The length or perimeter; 0 for points and multipoints.
public static double Length(this IGeometry2D geometry)Parameters
geometryIGeometry2D-
The geometry.
Returns
Exceptions
- ArgumentNullException
-
geometryisnull. - NotSupportedException
-
geometryis not a known geometry kind.
NearestPoints(IGeometry2D, IGeometry2D)
The two points, one on each geometry, whose distance is SpatialNET.Measures.Distance(SpatialNET.IGeometry2D,SpatialNET.IGeometry2D) (ADR 0019). If the geometries intersect, or one lies in the area of the other, both points are the same. Among several equally near pairs the first in input order is returned. Z and M are interpolated on their segment (ADR 0015).
public static (Coordinate OnA, Coordinate OnB)? NearestPoints(this IGeometry2D a, IGeometry2D b)Parameters
aIGeometry2D-
The first geometry.
bIGeometry2D-
The second geometry.
Returns
- (Coordinate OnA, Coordinate OnB)?
-
The pair, or
nullif either geometry is empty.
Exceptions
- ArgumentNullException
-
aorbisnull. - NotSupportedException
-
A geometry is not a known geometry kind.
PointOnSurface(IGeometry2D)
A point that lies on the geometry, without Z and M, null for an empty geometry (ADR 0019). For a polygon
it is an interior point (the widest stretch of a horizontal line through the envelope), for a polyline the
interior vertex nearest to the centroid (or the middle of the line), for points the point nearest to the centroid.
public static Coordinate? PointOnSurface(this IGeometry2D geometry)Parameters
geometryIGeometry2D-
The geometry.
Returns
Exceptions
- ArgumentNullException
-
geometryisnull. - NotSupportedException
-
geometryis not a known geometry kind.