Table of Contents

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.

Instances of this class are thread-safe.

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

coordinateSequenceFactory CoordinateSequenceFactory

GeometryFactory(PrecisionModel)

Constructs a GeometryFactory that generates Geometries having the given {PrecisionModel} and the default CoordinateSequence implementation.

public GeometryFactory(PrecisionModel precisionModel)

Parameters

precisionModel PrecisionModel

The 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

precisionModel PrecisionModel

The PrecisionModel to use.

srid int

The 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

precisionModel PrecisionModel
srid int
coordinateSequenceFactory CoordinateSequenceFactory

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

precisionModel PrecisionModel

A precision model

srid int

A spatial reference id

coordinateSequenceFactory CoordinateSequenceFactory

A coordinate sequence factory

services NtsGeometryServices

NtsGeometryServices object creating this factory

Fields

Default

A predefined GeometryFactory with PrecisionModelc == Floating.

public static readonly GeometryFactory Default

Field Value

GeometryFactory

Fixed

A predefined GeometryFactory with PrecisionModel == Fixed.

public static readonly GeometryFactory Fixed

Field Value

GeometryFactory

Floating

A predefined GeometryFactory with PrecisionModel == Floating.

public static readonly GeometryFactory Floating

Field Value

GeometryFactory

Remarks

A shortcut for Default.

FloatingSingle

public static readonly GeometryFactory FloatingSingle

Field Value

GeometryFactory

Properties

CoordinateSequenceFactory

public CoordinateSequenceFactory CoordinateSequenceFactory { get; }

Property Value

CoordinateSequenceFactory

GeometryServices

Gets a value indicating the NtsGeometryServices object that created this factory.

public NtsGeometryServices GeometryServices { get; }

Property Value

NtsGeometryServices

PrecisionModel

Returns the PrecisionModel that Geometries created by this factory will be associated with.

public PrecisionModel PrecisionModel { get; }

Property Value

PrecisionModel

SRID

The SRID value defined for this factory.

public int SRID { get; }

Property Value

int

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

geomList IEnumerable<Geometry>

The Geometry to 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

dimension Dimension

The required dimension (Dontcare, Point, Curve or Surface)

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

g Geometry

The geometry

Returns

Geometry

A deep copy of the input geometry, using the CoordinateSequence type of this factory

See Also

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

geometries Geometry[]

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

coordinates CoordinateSequence

A 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

coordinates Coordinate[]

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

coordinates CoordinateSequence

A 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

coordinates Coordinate[]

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

lineStrings LineString[]

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

coordinates CoordinateSequence

A 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

point Point[]

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

coordinates Coordinate[]

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

polygons Polygon[]

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

coordinate Coordinate

a Coordinate, or null

Returns

Point

A Point object

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

coordinates CoordinateSequence

a CoordinateSequence (possibly empty), or null

Returns

Point

A Point object

CreatePointFromInternalCoord(Coordinate, Geometry)

public static Point CreatePointFromInternalCoord(Coordinate coord, Geometry exemplar)

Parameters

coord Coordinate
exemplar Geometry

Returns

Point

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

coordinates CoordinateSequence

the outer boundary of the new Polygon, or null or an empty LinearRing if the empty geometry is to be created.

Returns

Polygon

A Polygon object

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

coordinates Coordinate[]

the outer boundary of the new Polygon, or null or an empty LinearRing if the empty geometry is to be created.

Returns

Polygon

A Polygon object

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

shell LinearRing

the outer boundary of the new Polygon, or null or an empty LinearRing if 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

shell LinearRing

The outer boundary of the new Polygon, or null or an empty LinearRing if the empty point is to be created.

holes LinearRing[]

The inner boundaries of the new Polygon, or null or empty LinearRing s if the empty point is to be created.

Returns

Polygon

A Polygon object

OnDeserialized(StreamingContext)

[OnDeserialized]
protected void OnDeserialized(StreamingContext context)

Parameters

context StreamingContext

ToGeometry(Envelope)

Creates a Geometry with the same extent as the given envelope.

public virtual Geometry ToGeometry(Envelope envelope)

Parameters

envelope Envelope

The Envelope

Returns

Geometry

An empty Point (for null Envelopes), a Point (when min x = max x and min y = max y) or a Polygon (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

geometries IEnumerable<Geometry>

The IEnumerable of Geometry's to convert.

Returns

Geometry[]

The IEnumerable in array format.

ToLineStringArray(IEnumerable<Geometry>)

Converts the IEnumerable to an array.

public static LineString[] ToLineStringArray(IEnumerable<Geometry> lineStrings)

Parameters

lineStrings IEnumerable<Geometry>

The IEnumerable of LineStrings to convert.

Returns

LineString[]

The IEnumerable in array format.

ToLinearRingArray(IEnumerable<Geometry>)

Converts the IEnumerable to an array.

public static LinearRing[] ToLinearRingArray(IEnumerable<Geometry> linearRings)

Parameters

linearRings IEnumerable<Geometry>

The IEnumerable of LinearRings to convert.

Returns

LinearRing[]

The IEnumerable in array format.

ToMultiLineStringArray(IEnumerable<Geometry>)

Converts the IEnumerable to an array.

public static MultiLineString[] ToMultiLineStringArray(IEnumerable<Geometry> multiLineStrings)

Parameters

multiLineStrings IEnumerable<Geometry>

The IEnumerable of MultiLineStrings to convert.

Returns

MultiLineString[]

The IEnumerable in array format.

ToMultiPointArray(IEnumerable<Geometry>)

Converts the IEnumerable to an array.

public static MultiPoint[] ToMultiPointArray(IEnumerable<Geometry> multiPoints)

Parameters

multiPoints IEnumerable<Geometry>

The IEnumerable of MultiPoints to convert.

Returns

MultiPoint[]

The IEnumerable in array format.

ToMultiPolygonArray(IEnumerable<Geometry>)

Converts the IEnumerable to an array.

public static MultiPolygon[] ToMultiPolygonArray(IEnumerable<Geometry> multiPolygons)

Parameters

multiPolygons IEnumerable<Geometry>

The IEnumerable of MultiPolygons to convert.

Returns

MultiPolygon[]

The IEnumerable in array format.

ToPointArray(IEnumerable<Geometry>)

Converts the IEnumerable to an array.

public static Point[] ToPointArray(IEnumerable<Geometry> points)

Parameters

points IEnumerable<Geometry>

The IEnumerable of Points to convert.

Returns

Point[]

The IEnumerable in array format.

ToPolygonArray(IEnumerable<Geometry>)

Converts the IEnumerable to an array.

public static Polygon[] ToPolygonArray(IEnumerable<Geometry> polygons)

Parameters

polygons IEnumerable<Geometry>

The IEnumerable of Polygons to convert.

Returns

Polygon[]

The IEnumerable in array format.

ToString()

public override string ToString()

Returns

string

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

srid int

The SRID for the result.

Returns

GeometryFactory

The cloned instance.