Class Geometry
- Namespace
- NetTopologySuite.Geometries
- Assembly
- NetTopologySuite.dll
A representation of a planar, linear vector geometry.
public abstract class Geometry : IComparable, IComparable<Geometry>
- Inheritance
-
Geometry
- Implements
- Derived
- Inherited Members
Remarks
Binary Predicates:
Because it is not clear at this time what semantics for spatial analysis methods involvingGeometryCollection
s would be useful,
GeometryCollection
s are not supported as arguments to binary
predicates or the Relate
method.
Overlay Methods:
The spatial analysis methods will return the most specific class possible to represent the result. If the result is homogeneous, aPoint
, LineString
, or
Polygon
will be returned if the result contains a single
element; otherwise, a MultiPoint
, MultiLineString
,
or MultiPolygon
will be returned. If the result is
heterogeneous a GeometryCollection
will be returned.
Representation of Computed Geometries:
The SFS states that the result
of a set-theoretic method is the "point-set" result of the usual
set-theoretic definition of the operation (SFS 3.2.21.1). However, there are
sometimes many ways of representing a point set as a Geometry
.
The SFS does not specify an unambiguous representation of a given point set
returned from a spatial analysis method. One goal of NTS is to make this
specification precise and unambiguous. NTS uses a canonical form for
Geometry
s returned from overlay methods. The canonical
form is a Geometry
which is simple and noded:
Simple means that the Geometry returned will be simple according to
the NTS definition of IsSimple
.
Noded applies only to overlays involving LineString
s. It
means that all intersection points on LineString
s will be
present as endpoints of LineString
s in the result.
This definition implies that non-simple geometries which are arguments to
spatial analysis methods must be subjected to a line-dissolve process to
ensure that the results are simple.
Constructed Points And The Precision Model:
The results computed by the set-theoretic methods may
contain constructed points which are not present in the input Geometry
s.
These new points arise from intersections between line segments in the
edges of the input Geometry
s. In the general case it is not
possible to represent constructed points exactly. This is due to the fact
that the coordinates of an intersection point may contain twice as many bits
of precision as the coordinates of the input line segments. In order to
represent these constructed points explicitly, NTS must truncate them to fit
the PrecisionModel
.
Unfortunately, truncating coordinates moves them slightly. Line segments
which would not be coincident in the exact result may become coincident in
the truncated representation. This in turn leads to "topology collapses" --
situations where a computed element has a lower dimension than it would in
the exact result.
When NTS detects topology collapses during the computation of spatial
analysis methods, it will throw an exception. If possible the exception will
report the location of the collapse.
Geometry Equality
There are two ways of comparing geometries for equality: structural equality and topological equality.Structural Equality
Structural Equality is provided by the EqualsExact(Geometry) method. This implements a comparison based on exact, structural pointwise equality. The Equals(object) is a synonym for this method, to provide structural equality semantics for use in collections. It is important to note that structural pointwise equality is easily affected by things like ring order and component order. In many situations it will be desirable to normalize geometries before comparing them (using the Normalized() or Normalize() methods). EqualsNormalized(Geometry) is provided as a convenience method to compute equality over normalized geometries, but it is expensive to use. Finally, EqualsExact(Geometry, double) allows using a tolerance value for point comparison.Topological Equality
Topological Equality is provided by the EqualsTopologically(Geometry) method. It implements the SFS definition of point-set equality defined in terms of the DE-9IM matrix. To support the SFS naming convention, the method Equals(Geometry) is also provided as a synonym. However, due to the potential for confusion with Equals(object) its use is discouraged.Since Equals(object) and GetHashCode() are overridden, Geometries can be used effectively in .Net collections.
Constructors
Geometry(GeometryFactory)
Creates a new Geometry
via the specified GeometryFactory.
protected Geometry(GeometryFactory factory)
Parameters
factory
GeometryFactoryThe factory
Fields
DefaultFactory
A predefined GeometryFactory with PrecisionModel ==
Fixed.
public static readonly GeometryFactory DefaultFactory
Field Value
- See Also
TypeNameGeometryCollection
The name of geometry collection geometries.
public const string TypeNameGeometryCollection = "GeometryCollection"
Field Value
TypeNameLineString
The name of linestring geometries
public const string TypeNameLineString = "LineString"
Field Value
TypeNameLinearRing
The name of linearring geometries
public const string TypeNameLinearRing = "LinearRing"
Field Value
TypeNameMultiLineString
The name of multi-linestring geometries
public const string TypeNameMultiLineString = "MultiLineString"
Field Value
TypeNameMultiPoint
The name of multi-point geometries
public const string TypeNameMultiPoint = "MultiPoint"
Field Value
TypeNameMultiPolygon
The name of multi-polygon geometries
public const string TypeNameMultiPolygon = "MultiPolygon"
Field Value
TypeNamePoint
The name of point geometries
public const string TypeNamePoint = "Point"
Field Value
TypeNamePolygon
The name of polygon geometries
public const string TypeNamePolygon = "Polygon"
Field Value
Properties
Area
Returns the area of this Geometry
.
Areal Geometries have a non-zero area.
They override this function to compute the area.
Others return 0.0
public virtual double Area { get; }
Property Value
- double
The area of the Geometry.
Boundary
Returns the boundary, or an empty geometry of appropriate dimension
if this Geometry
is empty.
For a discussion of this function, see the OpenGIS Simple
Features Specification. As stated in SFS Section 2.1.13.1, "the boundary
of a Geometry is a set of Geometries of the next lower dimension."
public abstract Geometry Boundary { get; }
Property Value
- Geometry
The closure of the combinatorial boundary of this
Geometry
.
BoundaryDimension
Returns the dimension of this Geometry
s inherent boundary.
public abstract Dimension BoundaryDimension { get; }
Property Value
- Dimension
The dimension of the boundary of the class implementing this interface, whether or not this object is the empty point. Returns
Dimension.False
if the boundary is the empty point.
Centroid
Computes the centroid of this Geometry
.
The centroid
is equal to the centroid of the set of component Geometries of highest
dimension (since the lower-dimension geometries contribute zero
"weight" to the centroid).
POINT EMPTY
.
public virtual Point Centroid { get; }
Property Value
- Point
A Point which is the centroid of this Geometry.
Coordinate
Returns a vertex of this Geometry
(usually, but not necessarily, the first one).
public abstract Coordinate Coordinate { get; }
Property Value
- Coordinate
a Coordinate which is a vertex of this
Geometry
.
Remarks
The returned coordinate should not be assumed to be an actual Coordinate object used in the internal representation.
Coordinates
Returns an array containing the values of all the vertices for this geometry.
public abstract Coordinate[] Coordinates { get; }
Property Value
- Coordinate[]
The vertices of this
Geometry
.
Remarks
If the geometry is a composite, the array will contain all the vertices for the components, in the order in which the components occur in the geometry.
In general, the array cannot be assumed to be the actual internal storage for the vertices. Thus modifying the array may not modify the geometry itself. Use the SetOrdinate(int, int, double) or SetOrdinate(int, Ordinate, double) method (possibly on the components) to modify the underlying data. If the coordinates are modified, GeometryChanged() must be called afterwards.
- See Also
Dimension
Returns the dimension of this geometry.
public abstract Dimension Dimension { get; }
Property Value
- Dimension
The topological dimensions of this geometry
Remarks
The dimension of a geometry is is the topological dimension of its embedding in the 2-D Euclidean plane. In the NTS spatial model, dimension values are in the set {0,1,2}.
Note that this is a different concept to the dimension of the vertex Coordinates. The geometry dimension can never be greater than the coordinate dimension. For example, a 0-dimensional geometry (e.g. a Point) may have a coordinate dimension of 3 (X,Y,Z).
Envelope
Gets a geometry representing the envelope (bounding box) of this Geometry
.
public Geometry Envelope { get; }
Property Value
- Geometry
A Geometry representing the envelope of this Geometry
Remarks
If this Geometry
is
- empty, returns an empty
Point
- a point, returns a
Point
- a line parallel to an axis, a two-vertex
LineString
, - otherwise, returns a
Polygon
whose vertices are (minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy), (minx, miny).
- See Also
EnvelopeInternal
Gets an Envelope containing
the minimum and maximum x and y values in this Geometry
.
If the geometry is empty, an empty Envelope
is returned.
public Envelope EnvelopeInternal { get; }
Property Value
- Envelope
the envelope of this
Geometry
.
Remarks
The returned object is a copy of the one maintained internally, to avoid aliasing issues. For best performance, clients which access this envelope frequently should cache the return value.
Factory
Gets the factory which contains the context in which this point was created.
public GeometryFactory Factory { get; }
Property Value
- GeometryFactory
The factory for this point.
GeometryType
Returns the name of this Geometry's actual class.
public abstract string GeometryType { get; }
Property Value
- string
The name of this
Geometry
s actual class.
InteriorPoint
Computes an interior point of this Geometry
.
public virtual Point InteriorPoint { get; }
Property Value
- Point
A
Point
which is in the interior of this Geometry.
Remarks
An interior point is guaranteed to lie in the interior of the Geometry, if it possible to calculate such a point exactly. Otherwise, the point may lie on the boundary of the point.
The interior point of an empty geometry isPOINT EMPTY
.
IsEmpty
Tests whether the set of points covered in this Geometry
is empty.
A collection containing only empty elements is reported as empty.
To check structural emptiness use NumGeometries.
public abstract bool IsEmpty { get; }
Property Value
- bool
true
if thisGeometry
does not cover any points.
IsGeometryCollection
Tests whether this is an instance of a general {@link GeometryCollection}, rather than a homogeneous subclass.
protected bool IsGeometryCollection { get; }
Property Value
- bool
true
if this is a heterogeneous GeometryCollection
IsRectangle
Tests whether this is a rectangular Polygon.
public virtual bool IsRectangle { get; }
Property Value
- bool
true
if the geometry is a rectangle.
Remarks
Polygon overrides to check for actual rectangle.
IsSimple
Tests whether this Geometry is simple.
The SFS definition of simplicity follows the general rule that a Geometry is simple if it has no points of self-tangency, self-intersection or other anomalous points. Simplicity is defined for each Geometry subclass as follows:- Valid polygonal geometries are simple, since their rings
must not self-intersect.
IsSimple
tests for this condition and reportsfalse
if it is not met. (This is a looser test than checking for validity). - Linear rings have the same semantics.
- Linear geometries are simple if they do not self-intersect at points other than boundary points.
- Zero-dimensional geometries (points) are simple if they have no repeated points.
- Empty
Geometry
s are always simple.
public virtual bool IsSimple { get; }
Property Value
- bool
true
if thisGeometry
is simple
- See Also
IsValid
Tests whether this Geometry
is topologically
valid, according to the OGC SFS specification.
public virtual bool IsValid { get; }
Property Value
- bool
true
if thisGeometry
is valid.
Length
Returns the length of this Geometry
.
Linear geometries return their length.
Areal geometries return their perimeter.
They override this function to compute the length.
Others return 0.0
public virtual double Length { get; }
Property Value
- double
The length of the Geometry.
NumGeometries
Returns the number of Geometryes in a GeometryCollection, or 1, if the geometry is not a collection.
public virtual int NumGeometries { get; }
Property Value
NumPoints
Returns the count of this Geometry
s vertices. The Geometry
s contained by composite Geometry
s must be
Geometry's; that is, they must implement NumPoints
.
public abstract int NumPoints { get; }
Property Value
- int
The number of vertices in this
Geometry
.
OgcGeometryType
Gets the OGC geometry type
public abstract OgcGeometryType OgcGeometryType { get; }
Property Value
PointOnSurface
public Point PointOnSurface { get; }
Property Value
PrecisionModel
Returns the PrecisionModel
used by the Geometry
.
public PrecisionModel PrecisionModel { get; }
Property Value
- PrecisionModel
the specification of the grid of allowable points, for this
Geometry
and all otherGeometry
s.
SRID
Sets the ID of the Spatial Reference System used by the Geometry
.
public int SRID { get; set; }
Property Value
Remarks
NOTE: This method should only be used for exceptional circumstances or
for backwards compatibility. Normally the SRID
should be set on the
GeometryFactory used to create the geometry.
SRID
s set using this method will change the Factory.
- See Also
SortIndex
Gets a value to sort the geometry
protected abstract Geometry.SortIndexValue SortIndex { get; }
Property Value
Remarks
NOTE:
For JTS v1.17 this property's getter has been renamed to getTypeCode()
.
In order not to break binary compatibility we did not follow.
UserData
Gets/Sets the user data object for this point, if any.
public object UserData { get; set; }
Property Value
Remarks
A simple scheme for applications to add their own custom data to a Geometry. An example use might be to add an object representing a Coordinate Reference System. Note that user data objects are not present in geometries created by construction methods.
Methods
Apply(ICoordinateFilter)
Performs an operation with or on this Geometry
's coordinates.
public abstract void Apply(ICoordinateFilter filter)
Parameters
filter
ICoordinateFilterThe filter to apply to this
Geometry
's coordinates
Remarks
If this method modifies any coordinate values, GeometryChanged() must be called to update the geometry state. Note that you cannot use this method to modify this Geometry if its underlying CoordinateSequence's #get method returns a copy of the Coordinate, rather than the actual Coordinate stored (if it even stores Coordinate objects at all).
Apply(ICoordinateSequenceFilter)
Performs an operation on the coordinates in this Geometry
's CoordinateSequences.
public abstract void Apply(ICoordinateSequenceFilter filter)
Parameters
filter
ICoordinateSequenceFilterThe filter to apply
Remarks
If the filter reports that a coordinate value has been changed, GeometryChanged() will be called automatically.
Apply(IEntireCoordinateSequenceFilter)
Performs an operation on this Geometry
's CoordinateSequences.
public virtual void Apply(IEntireCoordinateSequenceFilter filter)
Parameters
filter
IEntireCoordinateSequenceFilterThe filter to apply
Remarks
If the filter reports that a coordinate value has been changed, GeometryChanged() will be called automatically.
Apply(IGeometryComponentFilter)
Performs an operation with or on this Geometry and its component Geometry's. Only GeometryCollections and Polygons have component Geometry's; for Polygons they are the LinearRings of the shell and holes.
public abstract void Apply(IGeometryComponentFilter filter)
Parameters
filter
IGeometryComponentFilterThe filter to apply to this
Geometry
.
Apply(IGeometryFilter)
Performs an operation with or on this Geometry
and its
subelement Geometry
s (if any).
Only GeometryCollections and subclasses
have subelement Geometry's.
public abstract void Apply(IGeometryFilter filter)
Parameters
filter
IGeometryFilterThe filter to apply to this
Geometry
(and its children, if it is aGeometryCollection
).
AsBinary()
public byte[] AsBinary()
Returns
- byte[]
AsText()
public string AsText()
Returns
Buffer(double)
Computes a buffer area around this geometry having the given width. The
buffer of a Geometry is the Minkowski sum or difference of the geometry
with a disc of radius Abs(distance)
.
public Geometry Buffer(double distance)
Parameters
distance
doubleThe width of the buffer (may be positive, negative or 0), interpreted according to the
PrecisionModel
of theGeometry
.
Returns
- Geometry
a polygonal geometry representing the buffer region (which may be empty)
Remarks
Mathematically-exact buffer area boundaries can contain circular arcs. To represent these arcs using linear geometry they must be approximated with line segments. The buffer geometry is constructed using 8 segments per quadrant to approximate the circular arcs.
The end cap style is EndCapStyle.Round
.
The buffer operation always returns a polygonal result. The negative or zero-distance buffer of lines and points is always an empty IPolygonal. This is also the result for the buffers of degenerate (zero-area) polygons.
Exceptions
- TopologyException
If a robustness error occurs
- See Also
Buffer(double, BufferParameters)
Computes a buffer region around this Geometry
having the given
width and with a specified number of segments used to approximate curves.
The buffer of a Geometry is the Minkowski sum of the Geometry with
a disc of radius distance
. Curves in the buffer polygon are
approximated with line segments. This method allows specifying the
accuracy of that approximation.
public Geometry Buffer(double distance, BufferParameters bufferParameters)
Parameters
distance
doubleThe width of the buffer, interpreted according to the
PrecisionModel
of theGeometry
.bufferParameters
BufferParametersThis argument type has a number of properties that control the construction of the buffer, including
QuadrantSegments
,EndCapStyle
,JoinStyle
, andMitreLimit
Returns
- Geometry
a polygonal geometry representing the buffer region (which may be empty)
Remarks
Mathematically-exact buffer area boundaries can contain circular arcs.
To represent these arcs using linear geometry they must be approximated with line segments.
The bufferParameters
argument has a property QuadrantSegments
controlling the accuracy of
the approximation by specifying the number of line segments used to
represent a quadrant of a circle
The EndCapStyle
property of the bufferParameters
argument specifies the buffer geometry that will be
created at the ends of linestrings. The styles provided are:
- Round - (default) a semi-circle
- Flat - a straight line perpendicular to the end segment
- Square - a half-square
The buffer operation always returns a polygonal result. The negative or zero-distance buffer of lines and points is always an empty IPolygonal. This is also the result for the buffers of degenerate (zero-area) polygons.
Exceptions
- TopologyException
If a robustness error occurs
- See Also
Buffer(double, EndCapStyle)
Computes a buffer region around this Geometry
having the given width.
The buffer of a Geometry is the Minkowski sum or difference of the geometry
with a disc of radius Abs(distance)
.
public Geometry Buffer(double distance, EndCapStyle endCapStyle)
Parameters
distance
doubleThe width of the buffer, interpreted according to the
PrecisionModel
of theGeometry
.endCapStyle
EndCapStyleCap Style to use for compute buffer.
Returns
- Geometry
a polygonal geometry representing the buffer region (which may be empty)
Remarks
The end cap style specifies the buffer geometry that will be created at the ends of linestrings. The styles provided are:
- Round - (default) a semi-circle
- Flat - a straight line perpendicular to the end segment
- Square - a half-square
The buffer operation always returns a polygonal result. The negative or zero-distance buffer of lines and points is always an empty IPolygonal.
Exceptions
- TopologyException
If a robustness error occurs
- See Also
Buffer(double, int)
Computes a buffer region around this Geometry
having the given
width and with a specified accuracy of approximation for circular arcs.
The buffer of a Geometry is the Minkowski sum of the Geometry with
a disc of radius distance
. Curves in the buffer polygon are
approximated with line segments. This method allows specifying the
accuracy of that approximation.
public Geometry Buffer(double distance, int quadrantSegments)
Parameters
distance
doubleThe width of the buffer (may be positive, negative or 0), interpreted according to the
PrecisionModel
of theGeometry
.quadrantSegments
intThe number of segments to use to approximate a quadrant of a circle.
Returns
- Geometry
a polygonal geometry representing the buffer region (which may be empty)
Remarks
Mathematically-exact buffer area boundaries can contain circular arcs.
To represent these arcs using linear geometry they must be approximated with line segments.
The quadrantSegments
argument allows controlling the accuracy of
the approximation by specifying the number of line segments used to
represent a quadrant of a circle
The buffer operation always returns a polygonal result. The negative or zero-distance buffer of lines and points is always an empty IPolygonal. This is also the result for the buffers of degenerate (zero-area) polygons.
Exceptions
- TopologyException
If a robustness error occurs
- See Also
Buffer(double, int, EndCapStyle)
Computes a buffer region around this Geometry
having the given
width and with a specified number of segments used to approximate curves.
The buffer of a Geometry is the Minkowski sum of the Geometry with
a disc of radius distance
. Curves in the buffer polygon are
approximated with line segments. This method allows specifying the
accuracy of that approximation.
public Geometry Buffer(double distance, int quadrantSegments, EndCapStyle endCapStyle)
Parameters
distance
doubleThe width of the buffer, interpreted according to the
PrecisionModel
of theGeometry
.quadrantSegments
intThe number of segments to use to approximate a quadrant of a circle.
endCapStyle
EndCapStyleCap Style to use for compute buffer.
Returns
- Geometry
a polygonal geometry representing the buffer region (which may be empty)
Remarks
Mathematically-exact buffer area boundaries can contain circular arcs.
To represent these arcs using linear geometry they must be approximated with line segments.
The quadrantSegments
argument allows controlling the accuracy of
the approximation by specifying the number of line segments used to
represent a quadrant of a circle
The end cap style specifies the buffer geometry that will be created at the ends of linestrings. The styles provided are:
- Round - (default) a semi-circle
- Flat - a straight line perpendicular to the end segment
- Square - a half-square
The buffer operation always returns a polygonal result. The negative or zero-distance buffer of lines and points is always an empty IPolygonal. This is also the result for the buffers of degenerate (zero-area) polygons.
Exceptions
- TopologyException
If a robustness error occurs
- See Also
CheckNotGeometryCollection(Geometry)
Throws an exception if g
's type is a GeometryCollection
.
(Its subclasses do not trigger an exception).
protected static void CheckNotGeometryCollection(Geometry g)
Parameters
g
GeometryThe
Geometry
to check.
Exceptions
- ArgumentException
if
g
is aGeometryCollection
, but not one of its subclasses.
Compare(List<Geometry>, List<Geometry>)
Returns the first non-zero result of CompareTo
encountered as
the two Collection
s are iterated over. If, by the time one of
the iterations is complete, no non-zero result has been encountered,
returns 0 if the other iteration is also complete. If b
completes before a
, a positive number is returned; if a
before b, a negative number.
protected static int Compare(List<Geometry> a, List<Geometry> b)
Parameters
Returns
- int
The first non-zero
compareTo
result, if any; otherwise, zero.
CompareTo(Geometry)
Returns whether this Geometry
is greater than, equal to,
or less than another Geometry
.
public int CompareTo(Geometry geom)
Parameters
geom
GeometryA
Geometry
with which to compare thisGeometry
Returns
- int
A positive number, 0, or a negative number, depending on whether this object is greater than, equal to, or less than
o
, as defined in "Normal Form For Geometry" in the NTS Technical Specifications.
Remarks
If their classes are different, they are compared using the following ordering:
- Point (lowest),
- MultiPoint,
- LineString,
- LinearRing,
- MultiLineString,
- Polygon,
- MultiPolygon,
- GeometryCollection (highest).
Geometry
s have the same class, their first
elements are compared. If those are the same, the second elements are
compared, etc.
CompareTo(object)
Returns whether this Geometry
is greater than, equal to,
or less than another Geometry
.
public int CompareTo(object o)
Parameters
o
objectA
Geometry
with which to compare thisGeometry
Returns
- int
A positive number, 0, or a negative number, depending on whether this object is greater than, equal to, or less than
o
, as defined in "Normal Form For Geometry" in the NTS Technical Specifications.
Remarks
If their classes are different, they are compared using the following ordering:
- Point (lowest),
- MultiPoint,
- LineString,
- LinearRing,
- MultiLineString,
- Polygon,
- MultiPolygon,
- GeometryCollection (highest).
Geometry
s have the same class, their first
elements are compared. If those are the same, the second elements are
compared, etc.
CompareTo(object, IComparer<CoordinateSequence>)
Returns whether this Geometry
is greater than, equal to,
or less than another Geometry
, using the given
public int CompareTo(object o, IComparer<CoordinateSequence> comp)
Parameters
o
objectA
Geometry
with which to compare thisGeometry
comp
IComparer<CoordinateSequence>A
IComparer<CoordinateSequence>
Returns
- int
A positive number, 0, or a negative number, depending on whether this object is greater than, equal to, or less than
o
, as defined in "Normal Form For Geometry" in the NTS Technical Specifications.
Remarks
If their classes are different, they are compared using the following ordering:
- Point (lowest),
- MultiPoint,
- LineString,
- LinearRing,
- MultiLineString,
- Polygon,
- MultiPolygon,
- GeometryCollection (highest).
Geometry
s have the same class, their first
elements are compared. If those are the same, the second elements are
compared, etc.
CompareToSameClass(object)
Returns whether this Geometry
is greater than, equal to,
or less than another Geometry
having the same class.
protected abstract int CompareToSameClass(object o)
Parameters
o
objectA
Geometry
having the same class as thisGeometry
.
Returns
- int
A positive number, 0, or a negative number, depending on whether this object is greater than, equal to, or less than
o
, as defined in "Normal Form For Geometry" in the NTS Technical Specifications.
CompareToSameClass(object, IComparer<CoordinateSequence>)
Returns whether this Geometry
is greater than, equal to,
or less than another Geometry
of the same class.
using the given IComparer<T>.
protected abstract int CompareToSameClass(object o, IComparer<CoordinateSequence> comp)
Parameters
o
objectA
Geometry
having the same class as thisGeometry
comp
IComparer<CoordinateSequence>The comparer
Returns
- int
A positive number, 0, or a negative number, depending on whether this object is greater than, equal to, or less than
o
, as defined in "Normal Form For Geometry" in the JTS Technical Specifications
ComputeEnvelopeInternal()
Returns the minimum and maximum x and y values in this Geometry
,
or a null Envelope
if this Geometry
is empty.
Unlike EnvelopeInternal
, this method calculates the Envelope
each time it is called; EnvelopeInternal
caches the result
of this method.
protected abstract Envelope ComputeEnvelopeInternal()
Returns
- Envelope
This
Geometry
s bounding box; if theGeometry
is empty,Envelope.IsNull
will returntrue
.
Contains(Geometry)
Tests whether this geometry contains the argument geometry.
public virtual bool Contains(Geometry g)
Parameters
g
Geometrythe
Geometry
with which to compare thisGeometry
Returns
- bool
true
if thisGeometry
containsg
Remarks
The Contains
predicate has the following equivalent definitions:
- Every point of the other geometry is a point of this geometry, and the interiors of the two geometries have at least one point in common.
- The DE-9IM Intersection Matrix for the two geometries matches the pattern
[T*****FF*]
g.within(this)
(Contains
is the converse of Within(Geometry))
An implication of the definition is that "Geometries do not
contain their boundary". In other words, if a geometry A is a subset of
the points in the boundary of a geometry B, B.Contains(A) == false
.
(As a concrete example, take A to be a LineString which lies in the boundary of a Polygon B.)
For a predicate with similar behaviour but avoiding
this subtle limitation, see Covers(Geometry).
ConvexHull()
Returns the smallest convex Polygon
that contains all the
points in the Geometry
. This obviously applies only to Geometry
s which contain 3 or more points.
public virtual Geometry ConvexHull()
Returns
- Geometry
the minimum-area convex polygon containing this
Geometry
's points.
Copy()
Creates a deep copy of this Geometry object.
Coordinate sequences contained in it are copied.
All instance fields are copied
(i.e. the SRID
, EnvelopeInternal
and UserData
).
public Geometry Copy()
Returns
- Geometry
A deep copy of this geometry
Remarks
NOTE: The UserData object reference (if present) is copied, but the value itself is not copied. If a deep copy is required this must be performed by the caller.
CopyInternal()
An internal method to copy subclass-specific geometry data.
protected abstract Geometry CopyInternal()
Returns
- Geometry
A copy of the target geometry object.
CoveredBy(Geometry)
Tests whether this geometry is covered by the specified geometry.
public bool CoveredBy(Geometry g)
Parameters
g
Geometrythe
Geometry
with which to compare thisGeometry
Returns
- bool
true
if thisGeometry
is covered byg
Remarks
The CoveredBy
predicate has the following equivalent definitions:
- Every point of this geometry is a point of the other geometry.
- The DE-9IM Intersection Matrix for the two geometries matches
at least one of the following patterns:
[T*F**F***]
[*TF**F***]
[**FT*F***]
[**F*TF***]
g.Covers(this) == true
(CoveredBy
is the converse of Covers(Geometry))
false
.
This predicate is similar to Within(Geometry),
but is more inclusive (i.e. returns true
for more cases).
- See Also
Covers(Geometry)
Tests whether this geometry covers the argument geometry
public virtual bool Covers(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
Returns
- bool
true
if thisGeometry
coversg
Remarks
The covers
predicate has the following equivalent definitions:
- Every point of the other geometry is a point of this geometry.
- The DE-9IM Intersection Matrix for the two geometries matches at least
one of the following patterns:
[T*****FF*]
or[*T****FF*]
or[***T**FF*]
or[****T*FF*]
g.CoveredBy(this) == true
(covers
is the converse of CoveredBy(Geometry))
false
.
This predicate is similar to Contains(Geometry),
but is more inclusive (i.e. returns true
for more cases).
In particular, unlike Contains
it does not distinguish between
points in the boundary and in the interior of geometries.
For most situations, Covers
should be used in preference to Contains
.
As an added benefit, Covers
is more amenable to optimization,
and hence should be more performant.
- See Also
CreateArray(CoordinateSequence, Ordinate)
protected static double[] CreateArray(CoordinateSequence sequence, Ordinate ordinate)
Parameters
sequence
CoordinateSequenceordinate
Ordinate
Returns
- double[]
CreateArray(int, double)
protected static double[] CreateArray(int size, double value)
Parameters
Returns
- double[]
Crosses(Geometry)
Tests whether this geometry crosses the specified geometry.
public virtual bool Crosses(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
Returns
- bool
true
if the twoGeometry
s cross.
Remarks
The Crosses
predicate has the following equivalent definitions:
- The geometries have some but not all interior points in common.
- The DE-9IM Intersection Matrix for the two geometries matches
one of the following patterns:
Code Description [T*T******]
for P/L, P/A, and L/A situations [T*****T**]
for L/P, A/P, and A/L situations) [0********]
for L/L situations
false
.
The SFS defined this predicate only for P/L, P/A, L/L, and L/A situations. To make the relation symmetric, NTS extends the definition to apply to L/P, A/P and A/L situations as well.
Difference(Geometry)
Computes a Geometry
representing the closure of the point-set
of the points contained in this Geometry
that are not contained in
the other
Geometry.
public Geometry Difference(Geometry other)
Parameters
other
GeometryThe
Geometry
with which to compute the difference.
Returns
- Geometry
A Geometry representing the point-set difference of this
Geometry
withother
.
Exceptions
- ArgumentException
if the argument has a factory with a different
GeometryOverlay
object assigned
Disjoint(Geometry)
Tests whether this geometry is disjoint from the argument geometry.
public bool Disjoint(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
.
Returns
- bool
true
if the twoGeometry
s are disjoint.
Remarks
The Disjoint
predicate has the following equivalent definitions:
- The DE-9IM intersection matrix for the two geometries matches
FF*FF****
. !g.intersects(this) == true
(Disjoint
is the inverse ofIntersects
)
Distance(Geometry)
Returns the minimum distance between this Geometry
and another Geometry
g.
public virtual double Distance(Geometry g)
Parameters
g
GeometryThe
Geometry
from which to compute the distance.
Returns
- double
The distance between the geometries
Exceptions
- ArgumentException
if g is null
Equal(Coordinate, Coordinate, double)
[Obsolete("Will be removed in a future version")]
protected static bool Equal(Coordinate a, Coordinate b, double tolerance)
Parameters
a
Coordinateb
Coordinatetolerance
double
Returns
Equals(Geometry)
Tests whether this geometry is topologically equal to the argument geometry.
This method is included for backward compatibility reasons. It has been superseded by the EqualsTopologically(Geometry) method, which has been named to clearly denote its functionality. This method should NOT be confused with the method Equals(object), which implements an exact equality comparison.public bool Equals(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
Returns
- bool
true
if the twoGeometry
s are topologically equal.
- See Also
Equals(object)
Tests whether this geometry is structurally and numerically equal to a given Object.
public override bool Equals(object o)
Parameters
o
objectThe object to compare
Returns
- bool
true
if this geometry is exactly equal to the argument
Remarks
If the argument Object is not a Geometry
,
the result is false
.
Otherwise, the result is computed using
EqualsExact(Geometry).
Geometry
s as keys and values in Java collections.
Note that to produce the expected result the input geometries
should be in normal form. It is the caller's
responsibility to perform this where required
(using Normalized()
or Normalize() as appropriate).
- See Also
EqualsExact(Geometry)
Returns true if the two Geometry
s are exactly equal.
Two Geometries are exactly equal if:
- they have the same class,
- they have the same values of Coordinates in their internal Coordinate lists, in exactly the same order.
GeometryFactory
, the SRID
,
or the UserData
fields.
To properly test equality between different geometries,
it is usually necessary to Normalize() them first.
public bool EqualsExact(Geometry other)
Parameters
other
GeometryThe
Geometry
with which to compare thisGeometry
.
Returns
- bool
true
if this and the otherGeometry
have identical structure and point values.
EqualsExact(Geometry, double)
Returns true if the two Geometry
s are exactly equal,
up to a specified tolerance.
Two Geometries are exactly within a tolerance equal if:
- they have the same class,
- they have the same values of Coordinates, within the given tolerance distance, in their internal Coordinate lists, in exactly the same order.
GeometryFactory
, the SRID
,
or the UserData
fields.
To properly test equality between different geometries,
it is usually necessary to Normalize() them first.
public abstract bool EqualsExact(Geometry other, double tolerance)
Parameters
other
GeometryThe
Geometry
with which to compare thisGeometry
have identical structure and point values, up to the distance tolerance.tolerance
doubleDistance at or below which two Coordinates will be considered equal.
Returns
- bool
true
if this and the otherGeometry
are of the same class and have equal internal data.
- See Also
EqualsNormalized(Geometry)
Tests whether two geometries are exactly equal
in their normalized forms.
public bool EqualsNormalized(Geometry g)
Parameters
g
GeometryA geometry
Returns
- bool
true if the input geometries are exactly equal in their normalized form
- See Also
EqualsTopologically(Geometry)
Tests whether this geometry is topologically equal to the argument geometry
as defined by the SFS Equals
predicate.
public virtual bool EqualsTopologically(Geometry g)
Parameters
g
Geometrythe
Geometry
with which to compare thisGeometry
Returns
- bool
true
if the twoGeometry
s are topologically equal
Remarks
The SFS equals
predicate has the following equivalent definitions:
- The two geometries have at least one point in common, and no point of either geometry lies in the exterior of the other geometry.
- The DE-9IM Intersection Matrix for the two geometries matches
the pattern T*F**FFF*
T*F **F FF*
GeometryChanged()
Notifies this geometry that its coordinates have been changed by an external party (for example, via a ICoordinateFilter).
public void GeometryChanged()
Remarks
When this method is called the geometry will flush and/or update any derived information it has cached (such as its Envelope ). The operation is applied to all component Geometries.
GeometryChangedAction()
Notifies this Geometry that its Coordinates have been changed by an external party. When GeometryChanged is called, this method will be called for this Geometry and its component Geometries.
public void GeometryChangedAction()
GetGeometryN(int)
Returns an element Geometry from a GeometryCollection,
or this
, if the geometry is not a collection.
public virtual Geometry GetGeometryN(int n)
Parameters
n
intThe index of the geometry element.
Returns
- Geometry
The n'th geometry contained in this geometry.
GetHashCode()
Gets a hash code for the Geometry.
public override int GetHashCode()
Returns
- int
An integer value suitable for use as a hashcode
GetOrdinates(Ordinate)
Gets an array of double ordinate values
public abstract double[] GetOrdinates(Ordinate ordinate)
Parameters
ordinate
OrdinateThe ordinate index
Returns
- double[]
An array of ordinate values
HasNonEmptyElements(Geometry[])
Returns true if the array contains any non-empty Geometry
s.
protected static bool HasNonEmptyElements(Geometry[] geometries)
Parameters
geometries
Geometry[]an array of
Geometry
s; no elements may benull
Returns
- bool
true
if any of theGeometry
sIsEmpty
methods returnfalse
.
HasNullElements(object[])
Returns true if the array contains any null
elements.
[Obsolete("Use HasNullElements<T>")]
public static bool HasNullElements(object[] array)
Parameters
array
object[]an array to validate.
Returns
- bool
true
if any ofarray
s elements arenull
.
HasNullElements<T>(IEnumerable<T>)
Returns true if the array contains any null
elements.
public static bool HasNullElements<T>(IEnumerable<T> array) where T : class
Parameters
array
IEnumerable<T>an array to validate.
Returns
- bool
true
if any ofarray
s elements arenull
.
Type Parameters
T
Intersection(Geometry)
Computes a Geometry
representing the point-set which is
common to both this Geometry
and the other
Geometry.
public Geometry Intersection(Geometry other)
Parameters
other
GeometryThe
Geometry
with which to compute the intersection.
Returns
- Geometry
A geometry representing the point-set common to the two
Geometry
s.
Exceptions
- TopologyException
if a robustness error occurs.
- ArgumentException
if the argument is a non-empty heterogeneous
GeometryCollection
- ArgumentException
if the argument has a factory with a different
GeometryOverlay
object assigned
Intersects(Geometry)
Tests whether this geometry intersects the argument geometry.
public virtual bool Intersects(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
.
Returns
- bool
true
if the twoGeometry
s intersect.
Remarks
The Intersects
predicate has the following equivalent definitions:
- The two geometries have at least one point in common
- The DE-9IM Intersection Matrix for the two geometries matches
[T********]
or
[*T*******]
or
[***T*****]
or
[****T****]
!g.disjoint(this)
(Intersects
is the inverse ofDisjoint
)
IsEquivalentClass(Geometry)
Returns whether the two Geometry
s are equal, from the point
of view of the EqualsExact
method. Called by EqualsExact
. In general, two Geometry
classes are considered to be
"equivalent" only if they are the same class. An exception is LineString
, which is considered to be equivalent to its subclasses.
protected virtual bool IsEquivalentClass(Geometry other)
Parameters
other
GeometryThe
Geometry
with which to compare thisGeometry
for equality.
Returns
- bool
true
if the classes of the twoGeometry
s are considered to be equal by theequalsExact
method.
IsWithinDistance(Geometry, double)
Tests whether the distance from this Geometry
to another is less than or equal to a specified value.
public virtual bool IsWithinDistance(Geometry geom, double distance)
Parameters
Returns
- bool
true
if the geometries are less thandistance
apart.
Normalize()
Converts this Geometry
to normal form (or canonical form ).
public abstract void Normalize()
Remarks
Normal form is a unique representation for Geometry
s.
It can be used to test whether two Geometry
s are equal
in a way that is independent of the ordering of the coordinates within
them. Normal form equality is a stronger condition than topological
equality, but weaker than pointwise equality.
The definitions for normal form use the standard lexicographical ordering for coordinates. "Sorted in order of coordinates" means the obvious extension of this ordering to sequences of coordinates.
NOTE that this method mutates the value of this geometry in-place. If this is not safe and/or wanted, the geometry should be cloned prior to normalization.
Normalized()
Creates a new Geometry which is a normalized copy of this Geometry.
public Geometry Normalized()
Returns
- Geometry
A normalized copy of this geometry.
- See Also
Overlaps(Geometry)
Tests whether this geometry overlaps the specified geometry.
public virtual bool Overlaps(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
.
Returns
- bool
true
if the twoGeometry
s overlap. For this function to returntrue
, theGeometry
s must be two points, two curves or two surfaces.
Remarks
The Overlaps
predicate has the following equivalent definitions:
- The geometries have at least one point each not shared by the other (or equivalently neither covers the other), they have the same dimension, and the intersection of the interiors of the two geometries has the same dimension as the geometries themselves.
- The DE-9IM Intersection Matrix for the two geometries matches
[T*T***T**]
(for two points or two surfaces) or[1*T***T**]
(for two curves)
false
.
Relate(Geometry)
Returns the DE-9IM intersection matrix for the two Geometry
s.
public virtual IntersectionMatrix Relate(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
Returns
- IntersectionMatrix
A matrix describing the intersections of the interiors, boundaries and exteriors of the two
Geometry
s.
Relate(Geometry, string)
Tests whether the elements in the DE-9IM
IntersectionMatrix for the two Geometry
s match the elements in intersectionPattern
.
public virtual bool Relate(Geometry g, string intersectionPattern)
Parameters
g
Geometrythe
Geometry
with which to compare thisGeometry
intersectionPattern
stringthe pattern against which to check the intersection matrix for the two
Geometry
s
Returns
- bool
true
if the DE-9IM intersection matrix for the twoGeometry
s matchintersectionPattern
Remarks
The pattern is a 9-character string, with symbols drawn from the following set:
0 | (dimension 0) |
1 | (dimension 1) |
2 | (dimension 2) |
T | ( matches 0, 1 or 2) |
F | ( matches FALSE) |
* | ( matches any value) |
- See Also
Reverse()
Computes a new geometry which has all component coordinate sequences in reverse order (opposite orientation) to this one.
public virtual Geometry Reverse()
Returns
- Geometry
A reversed geometry
Remarks
Don't override this function, implement ReverseInternal().
ReverseInternal()
The actual implementation of the Reverse() function
protected virtual Geometry ReverseInternal()
Returns
- Geometry
A reversed geometry
Remarks
In JTS this function is abstract, but that would break binary compatibility of current version.
SymmetricDifference(Geometry)
Computes a Geometry
representing the closure of the point-set
which is the union of the points in this Geometry
which are not
contained in the other
Geometry,
with the points in the other
Geometry not contained in this
Geometry
.
If the result is empty, it is an atomic geometry
with the dimension of the highest input dimension.
public Geometry SymmetricDifference(Geometry other)
Parameters
other
GeometryThe
Geometry
with which to compute the symmetric difference.
Returns
- Geometry
a Geometry representing the point-set symmetric difference of this
Geometry
withother
.
Exceptions
- ArgumentException
if the argument has a factory with a different
GeometryOverlay
object assigned
ToBinary()
Returns the Well-known Binary representation of this Geometry
.
For a definition of the Well-known Binary format, see the OpenGIS Simple
Features Specification.
public byte[] ToBinary()
Returns
- byte[]
The Well-known Binary representation of this
Geometry
.
ToGMLFeature()
Returns the feature representation as GML 2.1.1 XML document.
This XML document is based on Geometry.xsd
schema.
NO features or XLink are implemented here!
public XmlReader ToGMLFeature()
Returns
- XmlReader
ToString()
Returns the Well-known Text representation of this Geometry
.
For a definition of the Well-known Text format, see the OpenGIS Simple
Features Specification.
public override string ToString()
Returns
- string
The Well-known Text representation of this
Geometry
.
ToText()
Returns the Well-known Text representation of this Geometry
.
For a definition of the Well-known Text format, see the OpenGIS Simple
Features Specification.
public string ToText()
Returns
- string
The Well-known Text representation of this
Geometry
.
Touches(Geometry)
Tests whether this geometry touches the argument geometry
public virtual bool Touches(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
.
Returns
- bool
true
if the twoGeometry
s touch; Returns false if bothGeometry
s are points.
Remarks
The Touches
predicate has the following equivalent definitions:
- The geometries have at least one point in common, but their interiors do not intersect
- The DE-9IM Intersection Matrix for the two geometries matches
at least one of the following patterns
FT*******
,F**T*****
orF***T****
.
false
,
since points have only interiors.
This predicate is symmetric.
Union()
Computes the union of all the elements of this geometry.
public Geometry Union()
Returns
Remarks
This method supports GeometryCollections (which the other overlay operations currently do not).
Exceptions
- TopologyException
Thrown if a robustness error occurs
Union(Geometry)
Computes a Geometry
representing the point-set
which is contained in both this
Geometry
and the other
Geometry.
public Geometry Union(Geometry other)
Parameters
other
Geometrythe
Geometry
with which to compute the union
Returns
- Geometry
A point-set combining the points of this
Geometry
and the points ofother
Remarks
The method may be used on arguments of different dimension, but it does not support GeometryCollection arguments.
The union of two geometries of different dimension produces a result geometry of dimension equal to the maximum dimension of the input geometries. The result geometry may be a heterogeneous GeometryCollection. If the result is empty, it is an atomic geometry with the dimension of the highest input dimension. Unioning LineStrings has the effect of noding and dissolving the input linework. In this context "noding" means that there will be a node or endpoint in the result for every endpoint or line segment crossing in the input. "Dissolving" means that any duplicate (i.e. coincident) line segments or portions of line segments will be reduced to a single line segment in the result. If merged linework is required, the LineMerger class can be used. Non-empty GeometryCollection arguments are not supported.Exceptions
- TopologyException
Thrown if a robustness error occurs
- ArgumentException
Thrown if either input is a non-empty GeometryCollection
- ArgumentException
if the argument has a factory with a different
GeometryOverlay
object assigned
- See Also
Within(Geometry)
Tests whether this geometry is within the specified geometry.
public bool Within(Geometry g)
Parameters
g
GeometryThe
Geometry
with which to compare thisGeometry
.
Returns
- bool
true
if thisGeometry
is withinother
.
Remarks
The within
predicate has the following equivalent definitions:
- Every point of this geometry is a point of the other geometry, and the interiors of the two geometries have at least one point in common.
- The DE-9IM Intersection Matrix for the two geometries matches
[T*F**F***]
g.contains(this) == true
(Within
is the converse of Contains(Geometry))
An implication of the definition is that "The boundary of a geometry is not within the Polygon".
In other words, if a geometry A is a subset of the points in the boundary of a geometry B, A.within(B) == false
(As a concrete example, take A to be a LineString which lies in the boundary of a Polygon B.)
For a predicate with similar behaviour but avoiding
this subtle limitation, see CoveredBy(Geometry).
Operators
operator ==(Geometry, Geometry)
public static bool operator ==(Geometry obj1, Geometry obj2)
Parameters
Returns
operator !=(Geometry, Geometry)
public static bool operator !=(Geometry obj1, Geometry obj2)