Class GeometryTransformer
A framework for processes which transform an input Geometry into
an output Geometry, possibly changing its structure and type(s).
Inherited Members
Namespace: NetTopologySuite.Geometries.Utilities
Assembly: NetTopologySuite.dll
Syntax
public class GeometryTransformer
Remarks
This class is a framework for implementing subclasses which perform transformations on various different Geometry subclasses.
It provides an easy way of applying specific transformations
to given point types, while allowing unhandled types to be simply copied.
Also, the framework handles ensuring that if subcomponents change type
the parent geometries types change appropriately to maintain valid structure.
Subclasses will override whichever TransformX methods
they need to to handle particular Geometry types.
A typically usage would be a transformation that may transform Polygons into
Polygons, LineStrings or Points, depending on the geometry of the input
(For instance, a simplification operation).
This class would likely need to override the TransformMultiPolygon(MultiPolygon, Geometry)
method to ensure that if input Polygons change type the result is a GeometryCollection,
not a MultiPolygon.
The default behaviour of this class is simply to recursively transform each Geometry component into an identical object by deep copying down to the level of, but not including, coordinates.
Note that all TransformXXX methods may return null,
to avoid creating empty point objects. This will be handled correctly
by the transformer. TransformXXX methods should always return valid
geometry - if they cannot do this they should return null
(for instance, it may not be possible for a transformLineString implementation
to return at least two points - in this case, it should return null).
The Transform(Geometry) method itself will always
return a non-null Geometry object (but this may be empty).
Fields
| Edit this page View SourceFactory
The geometry factory
Declaration
protected GeometryFactory Factory
Field Value
| Type | Description |
|---|---|
| GeometryFactory |
Properties
| Edit this page View SourceInputGeometry
Makes the input geometry available
Declaration
public Geometry InputGeometry { get; }
Property Value
| Type | Description |
|---|---|
| Geometry |
Methods
| Edit this page View SourceCopy(CoordinateSequence)
Convenience method which provides a standard way of copying CoordinateSequences.
Declaration
protected virtual CoordinateSequence Copy(CoordinateSequence seq)
Parameters
| Type | Name | Description |
|---|---|---|
| CoordinateSequence | seq | The sequence to copy. |
Returns
| Type | Description |
|---|---|
| CoordinateSequence | A deep copy of the sequence. |
CreateCoordinateSequence(Coordinate[])
Convenience method which provides standard way of
creating a CoordinateSequence.
Declaration
protected virtual CoordinateSequence CreateCoordinateSequence(Coordinate[] coords)
Parameters
| Type | Name | Description |
|---|---|---|
| Coordinate[] | coords | The coordinate array to copy. |
Returns
| Type | Description |
|---|---|
| CoordinateSequence | A coordinate sequence for the array. |
Transform(Geometry)
Declaration
public Geometry Transform(Geometry inputGeom)
Parameters
| Type | Name | Description |
|---|---|---|
| Geometry | inputGeom |
Returns
| Type | Description |
|---|---|
| Geometry |
TransformCoordinates(CoordinateSequence, Geometry)
Transforms a CoordinateSequence. This method should always return a valid coordinate list for the desired result type. (E.g. a coordinate list for a LineString must have 0 or at least 2 points). If this is not possible, return an empty sequence - this will be pruned out.
Declaration
protected virtual CoordinateSequence TransformCoordinates(CoordinateSequence coords, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| CoordinateSequence | coords | The coordinates to transform |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| CoordinateSequence | The transformed coordinates |
TransformGeometryCollection(GeometryCollection, Geometry)
Transforms a GeometryCollection geometry.
Declaration
protected virtual Geometry TransformGeometryCollection(GeometryCollection geom, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| GeometryCollection | geom | The |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| Geometry | A |
TransformLineString(LineString, Geometry)
Transforms a LineString geometry.
Declaration
protected virtual Geometry TransformLineString(LineString geom, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| LineString | geom | The |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| Geometry | A |
TransformLinearRing(LinearRing, Geometry)
Transforms a LinearRing.
The transformation of aLinearRing may result in a coordinate sequence
which does not form a structurally valid ring (i.e. a degenerate ring of 3 or fewer points).
In this case a LineString is returned.
Subclasses may wish to override this method and check for this situation
(e.g.a subclass may choose to eliminate degenerate linear rings)
Declaration
protected virtual Geometry TransformLinearRing(LinearRing geom, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| LinearRing | geom | The |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| Geometry | A |
TransformMultiLineString(MultiLineString, Geometry)
Transforms a MultiLineString geometry.
Declaration
protected virtual Geometry TransformMultiLineString(MultiLineString geom, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| MultiLineString | geom | The |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| Geometry | A |
TransformMultiPoint(MultiPoint, Geometry)
Transforms a MultiPoint geometry.
Declaration
protected virtual Geometry TransformMultiPoint(MultiPoint geom, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| MultiPoint | geom | The |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| Geometry | A |
TransformMultiPolygon(MultiPolygon, Geometry)
Transforms a MultiPolygon geometry.
Declaration
protected virtual Geometry TransformMultiPolygon(MultiPolygon geom, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| MultiPolygon | geom | The |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| Geometry | A |
TransformPoint(Point, Geometry)
Transforms a Point geometry.
Declaration
protected virtual Geometry TransformPoint(Point geom, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | geom | The |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| Geometry | A |
TransformPolygon(Polygon, Geometry)
Transforms a Polygon geometry.
Declaration
protected virtual Geometry TransformPolygon(Polygon geom, Geometry parent)
Parameters
| Type | Name | Description |
|---|---|---|
| Polygon | geom | The |
| Geometry | parent | The parent geometry |
Returns
| Type | Description |
|---|---|
| Geometry | A |