Class GeometryFactory
- Namespace
- NetTopologySuite.Geometries
- Assembly
- NetTopologySuite.dll
Supplies a set of utility methods for building Geometry objects from lists of Coordinates.
public class GeometryFactory
- Inheritance
-
GeometryFactory
- Derived
- Inherited Members
Remarks
Note that the factory constructor methods do not change the input coordinates in any way.
In particular, they are not rounded to the supplied PrecisionModel.
It is assumed that input Coordinates meet the given precision.
Constructors
GeometryFactory()
Constructs a GeometryFactory that generates Geometries having a floating PrecisionModel and a spatial-reference ID of 0.
public GeometryFactory()
GeometryFactory(CoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given CoordinateSequence implementation, a double-precision floating PrecisionModel and a spatial-reference ID of 0.
public GeometryFactory(CoordinateSequenceFactory coordinateSequenceFactory)
Parameters
coordinateSequenceFactoryCoordinateSequenceFactory
GeometryFactory(PrecisionModel)
Constructs a GeometryFactory that generates Geometries having the given {PrecisionModel} and the default CoordinateSequence implementation.
public GeometryFactory(PrecisionModel precisionModel)
Parameters
precisionModelPrecisionModelThe PrecisionModel to use.
GeometryFactory(PrecisionModel, int)
Constructs a GeometryFactory that generates Geometries having the given
PrecisionModel and spatial-reference ID, and the default CoordinateSequence
implementation.
public GeometryFactory(PrecisionModel precisionModel, int srid)
Parameters
precisionModelPrecisionModelThe PrecisionModel to use.
sridintThe SRID to use.
GeometryFactory(PrecisionModel, int, CoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel, spatial-reference ID, and CoordinateSequence implementation.
public GeometryFactory(PrecisionModel precisionModel, int srid, CoordinateSequenceFactory coordinateSequenceFactory)
Parameters
precisionModelPrecisionModelsridintcoordinateSequenceFactoryCoordinateSequenceFactory
GeometryFactory(PrecisionModel, int, CoordinateSequenceFactory, NtsGeometryServices)
Constructs a GeometryFactory that generates Geometries having the given
precisionModel, srid,
coordinateSequenceFactory and
services.
public GeometryFactory(PrecisionModel precisionModel, int srid, CoordinateSequenceFactory coordinateSequenceFactory, NtsGeometryServices services)
Parameters
precisionModelPrecisionModelA precision model
sridintA spatial reference id
coordinateSequenceFactoryCoordinateSequenceFactoryA coordinate sequence factory
servicesNtsGeometryServicesNtsGeometryServicesobject creating this factory
Fields
Default
A predefined GeometryFactory with PrecisionModelc
== Floating.
public static readonly GeometryFactory Default
Field Value
Fixed
A predefined GeometryFactory with PrecisionModel
== Fixed.
public static readonly GeometryFactory Fixed
Field Value
Floating
A predefined GeometryFactory with PrecisionModel
== Floating.
public static readonly GeometryFactory Floating
Field Value
Remarks
A shortcut for Default.
FloatingSingle
A predefined GeometryFactory with PrecisionModel
== FloatingSingle.
public static readonly GeometryFactory FloatingSingle
Field Value
Properties
CoordinateSequenceFactory
public CoordinateSequenceFactory CoordinateSequenceFactory { get; }
Property Value
GeometryServices
Gets a value indicating the NtsGeometryServices object that created this factory.
public NtsGeometryServices GeometryServices { get; }
Property Value
PrecisionModel
Returns the PrecisionModel that Geometries created by this factory will be associated with.
public PrecisionModel PrecisionModel { get; }
Property Value
SRID
The SRID value defined for this factory.
public int SRID { get; }
Property Value
Methods
BuildGeometry(IEnumerable<Geometry>)
Build an appropriate Geometry, MultiGeometry, or
GeometryCollection to contain the Geometrys in
it.
public virtual Geometry BuildGeometry(IEnumerable<Geometry> geomList)
Parameters
geomListIEnumerable<Geometry>The
Geometryto combine.
Returns
- Geometry
A Geometry of the "smallest", "most type-specific" class that can contain the elements of
geomList.
Remarks
If geomList contains a single Polygon,
the Polygon is returned.
If geomList contains several Polygons, a
MultiPolygon is returned.
If geomList contains some Polygons and
some LineStrings, a GeometryCollection is
returned.
If geomList is empty, an empty GeometryCollection
is returned.
Note that this method does not "flatten" Geometries in the input, and hence if
any MultiGeometries are contained in the input a GeometryCollection containing
them will be returned.
CreateEmpty(Dimension)
Creates an empty atomic geometry of the given dimension. If passed a dimension of Dontcare will create an empty GeometryCollection.
public Geometry CreateEmpty(Dimension dimension)
Parameters
Returns
- Geometry
An empty atomic geometry of given dimension
CreateGeometry(Geometry)
Creates a deep copy of the input Geometry. The CoordinateSequenceFactory defined for this factory is used to copy the CoordinateSequences of the input geometry.
This is a convenient way to change the CoordinateSequence used to represent a geometry, or to change the factory used for a geometry. Copy() can also be used to make a deep copy, but it does not allow changing the CoordinateSequence type.public virtual Geometry CreateGeometry(Geometry g)
Parameters
gGeometryThe geometry
Returns
- Geometry
A deep copy of the input geometry, using the CoordinateSequence type of this factory
- See Also
-
Copy()
CreateGeometryCollection()
Creates an empty GeometryCollection
public GeometryCollection CreateGeometryCollection()
Returns
- GeometryCollection
An empty GeometryCollection
CreateGeometryCollection(Geometry[])
Creates a GeometryCollection using the given Geometries; a null or empty
array will create an empty GeometryCollection.
public virtual GeometryCollection CreateGeometryCollection(Geometry[] geometries)
Parameters
geometriesGeometry[]an array of Geometries, each of which may be empty but not null, or null
Returns
- GeometryCollection
A GeometryCollection object
CreateLineString()
Creates an empty LineString
public LineString CreateLineString()
Returns
- LineString
An empty LineString
CreateLineString(CoordinateSequence)
Creates a LineString using the given CoordinateSequence. A null or empty CoordinateSequence creates an empty LineString.
public virtual LineString CreateLineString(CoordinateSequence coordinates)
Parameters
coordinatesCoordinateSequenceA CoordinateSequence (possibly empty), or null.
Returns
- LineString
A LineString object
CreateLineString(Coordinate[])
Creates a LineString using the given Coordinates. A null or empty array creates an empty LineString.
public LineString CreateLineString(Coordinate[] coordinates)
Parameters
coordinatesCoordinate[]An array without null elements, or an empty array, or null.
Returns
- LineString
A LineString object
CreateLinearRing()
Creates an empty LinearRing
public LinearRing CreateLinearRing()
Returns
- LinearRing
An empty LinearRing
CreateLinearRing(CoordinateSequence)
Creates a LinearRing using the given CoordinateSequence; a null or empty CoordinateSequence
creates an empty LinearRing. The points must form a closed and simple
linestring. Consecutive points must not be equal.
public virtual LinearRing CreateLinearRing(CoordinateSequence coordinates)
Parameters
coordinatesCoordinateSequenceA CoordinateSequence (possibly empty), or null.
Returns
- LinearRing
A LinearRing object
Exceptions
- ArgumentException
If the ring is not closed, or has too few points
CreateLinearRing(Coordinate[])
Creates a LinearRing using the given Coordinates; a null or empty array
creates an empty LinearRing. The points must form a closed and simple
linestring. Consecutive points must not be equal.
public LinearRing CreateLinearRing(Coordinate[] coordinates)
Parameters
coordinatesCoordinate[]An array without null elements, or an empty array, or null.
Returns
- LinearRing
A LinearRing object
Exceptions
- ArgumentException
If the ring is not closed, or has too few points
CreateMultiLineString()
Creates an empty MultiLineString
public MultiLineString CreateMultiLineString()
Returns
- MultiLineString
An empty MultiLineString
CreateMultiLineString(LineString[])
Creates a MultiLineString using the given LineStrings; a null or empty
array will create an empty MultiLineString.
public virtual MultiLineString CreateMultiLineString(LineString[] lineStrings)
Parameters
lineStringsLineString[]LineStrings, each of which may be empty but not null-
Returns
- MultiLineString
A MultiLineString object
CreateMultiPoint()
Creates an empty MultiPoint
public MultiPoint CreateMultiPoint()
Returns
- MultiPoint
An empty MultiPoint
CreateMultiPoint(CoordinateSequence)
Creates a MultiPoint using the given CoordinateSequence. A null or empty CoordinateSequence will create an empty MultiPoint.
public MultiPoint CreateMultiPoint(CoordinateSequence coordinates)
Parameters
coordinatesCoordinateSequenceA CoordinateSequence (possibly empty), or
null.
Returns
- MultiPoint
A MultiPoint object
CreateMultiPoint(Point[])
Creates a MultiPoint using the given Points. A null or empty array will create an empty MultiPoint.
public virtual MultiPoint CreateMultiPoint(Point[] point)
Parameters
pointPoint[]An array (without null elements), or an empty array, or
null.
Returns
- MultiPoint
A MultiPoint object
CreateMultiPointFromCoords(Coordinate[])
Creates a MultiPoint using the given Coordinates. A null or empty array will create an empty MultiPoint.
public MultiPoint CreateMultiPointFromCoords(Coordinate[] coordinates)
Parameters
coordinatesCoordinate[]An array (without null elements), or an empty array, or
null
Returns
- MultiPoint
A MultiPoint object
CreateMultiPolygon()
Creates an empty MultiPolygon
public MultiPolygon CreateMultiPolygon()
Returns
- MultiPolygon
An empty MultiPolygon
CreateMultiPolygon(Polygon[])
Creates a MultiPolygon using the given Polygons; a null or empty array
will create an empty Polygon. The polygons must conform to the
assertions specified in the http://www.opengis.org/techno/specs.htm OpenGIS Simple Features
Specification for SQL.
public virtual MultiPolygon CreateMultiPolygon(Polygon[] polygons)
Parameters
polygonsPolygon[]Polygons, each of which may be empty but not null.
Returns
- MultiPolygon
A MultiPolygon object
CreatePoint()
Creates an empty Point
public Point CreatePoint()
Returns
- Point
An empty Point
CreatePoint(Coordinate)
Creates a Point using the given Coordinate.
A null coordinate creates an empty Geometry.
public Point CreatePoint(Coordinate coordinate)
Parameters
coordinateCoordinatea Coordinate, or null
Returns
CreatePoint(CoordinateSequence)
Creates a Point using the given CoordinateSequence; a null or empty
CoordinateSequence will create an empty Point.
public virtual Point CreatePoint(CoordinateSequence coordinates)
Parameters
coordinatesCoordinateSequencea CoordinateSequence (possibly empty), or null
Returns
CreatePointFromInternalCoord(Coordinate, Geometry)
public static Point CreatePointFromInternalCoord(Coordinate coord, Geometry exemplar)
Parameters
coordCoordinateexemplarGeometry
Returns
CreatePolygon()
Creates an empty Polygon
public Polygon CreatePolygon()
Returns
- Polygon
An empty Polygon
CreatePolygon(CoordinateSequence)
Constructs a Polygon with the given exterior boundary.
public virtual Polygon CreatePolygon(CoordinateSequence coordinates)
Parameters
coordinatesCoordinateSequencethe outer boundary of the new
Polygon, ornullor an emptyLinearRingif the empty geometry is to be created.
Returns
Exceptions
- ArgumentException
If the boundary ring is invalid
CreatePolygon(Coordinate[])
Constructs a Polygon with the given exterior boundary.
public virtual Polygon CreatePolygon(Coordinate[] coordinates)
Parameters
coordinatesCoordinate[]the outer boundary of the new
Polygon, ornullor an emptyLinearRingif the empty geometry is to be created.
Returns
Exceptions
- ArgumentException
If the boundary ring is invalid
CreatePolygon(LinearRing)
Constructs a Polygon with the given exterior boundary.
public virtual Polygon CreatePolygon(LinearRing shell)
Parameters
shellLinearRingthe outer boundary of the new
Polygon, ornullor an emptyLinearRingif the empty geometry is to be created.
Returns
- Polygon
the created Polygon
Exceptions
- ArgumentException
If the boundary ring is invalid
CreatePolygon(LinearRing, LinearRing[])
Constructs a Polygon with the given exterior boundary and
interior boundaries.
public virtual Polygon CreatePolygon(LinearRing shell, LinearRing[] holes)
Parameters
shellLinearRingThe outer boundary of the new
Polygon, ornullor an emptyLinearRingif the empty point is to be created.holesLinearRing[]The inner boundaries of the new
Polygon, ornullor emptyLinearRings if the empty point is to be created.
Returns
OnDeserialized(StreamingContext)
[OnDeserialized]
protected void OnDeserialized(StreamingContext context)
Parameters
contextStreamingContext
ToGeometry(Envelope)
Creates a Geometry with the same extent as the given envelope.
public virtual Geometry ToGeometry(Envelope envelope)
Parameters
envelopeEnvelopeThe
Envelope
Returns
- Geometry
An empty
Point(for nullEnvelopes), aPoint(when min x = max x and min y = max y) or aPolygon(in all other cases)
Remarks
The Geometry returned is guaranteed to be valid. To provide this behavior, the following cases occur:
If the Envelope is:
- null returns an empty Point
- a point returns a non-empty Point
- a line returns a two-point LineString
- a rectangle returns a Polygon whose points are (minx, maxy), (minx, maxy), (maxx, maxy), (maxx, miny).
ToGeometryArray(IEnumerable<Geometry>)
Converts the IEnumerable to an array.
public static Geometry[] ToGeometryArray(IEnumerable<Geometry> geometries)
Parameters
geometriesIEnumerable<Geometry>The
IEnumerableofGeometry's to convert.
Returns
- Geometry[]
The
IEnumerablein array format.
ToLineStringArray(IEnumerable<Geometry>)
Converts the IEnumerable to an array.
public static LineString[] ToLineStringArray(IEnumerable<Geometry> lineStrings)
Parameters
lineStringsIEnumerable<Geometry>The
IEnumerableof LineStrings to convert.
Returns
- LineString[]
The
IEnumerablein array format.
ToLinearRingArray(IEnumerable<Geometry>)
Converts the IEnumerable to an array.
public static LinearRing[] ToLinearRingArray(IEnumerable<Geometry> linearRings)
Parameters
linearRingsIEnumerable<Geometry>The
IEnumerableof LinearRings to convert.
Returns
- LinearRing[]
The
IEnumerablein array format.
ToMultiLineStringArray(IEnumerable<Geometry>)
Converts the IEnumerable to an array.
public static MultiLineString[] ToMultiLineStringArray(IEnumerable<Geometry> multiLineStrings)
Parameters
multiLineStringsIEnumerable<Geometry>The
IEnumerableof MultiLineStrings to convert.
Returns
- MultiLineString[]
The
IEnumerablein array format.
ToMultiPointArray(IEnumerable<Geometry>)
Converts the IEnumerable to an array.
public static MultiPoint[] ToMultiPointArray(IEnumerable<Geometry> multiPoints)
Parameters
multiPointsIEnumerable<Geometry>The
IEnumerableof MultiPoints to convert.
Returns
- MultiPoint[]
The
IEnumerablein array format.
ToMultiPolygonArray(IEnumerable<Geometry>)
Converts the IEnumerable to an array.
public static MultiPolygon[] ToMultiPolygonArray(IEnumerable<Geometry> multiPolygons)
Parameters
multiPolygonsIEnumerable<Geometry>The
IEnumerableof MultiPolygons to convert.
Returns
- MultiPolygon[]
The
IEnumerablein array format.
ToPointArray(IEnumerable<Geometry>)
Converts the IEnumerable to an array.
public static Point[] ToPointArray(IEnumerable<Geometry> points)
Parameters
pointsIEnumerable<Geometry>The
IEnumerableof Points to convert.
Returns
- Point[]
The
IEnumerablein array format.
ToPolygonArray(IEnumerable<Geometry>)
Converts the IEnumerable to an array.
public static Polygon[] ToPolygonArray(IEnumerable<Geometry> polygons)
Parameters
polygonsIEnumerable<Geometry>The
IEnumerableof Polygons to convert.
Returns
- Polygon[]
The
IEnumerablein array format.
ToString()
public override string ToString()
Returns
WithSRID(int)
Returns a new GeometryFactory whose SRID is the given value and whose other values and behavior are, as near as we possibly can make it, the same as our own.
public virtual GeometryFactory WithSRID(int srid)
Parameters
Returns
- GeometryFactory
The cloned instance.