Class GeometryTransformer
- Namespace
- NetTopologySuite.Geometries.Utilities
- Assembly
- NetTopologySuite.dll
A framework for processes which transform an input Geometry
into
an output Geometry, possibly changing its structure and type(s).
public class GeometryTransformer
- Inheritance
-
GeometryTransformer
- Inherited Members
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).
Constructors
GeometryTransformer()
public GeometryTransformer()
Fields
Factory
The geometry factory
protected GeometryFactory Factory
Field Value
Properties
InputGeometry
Makes the input geometry available
public Geometry InputGeometry { get; }
Property Value
Methods
Copy(CoordinateSequence)
Convenience method which provides a standard way of copying CoordinateSequences.
protected virtual CoordinateSequence Copy(CoordinateSequence seq)
Parameters
seq
CoordinateSequenceThe sequence to copy.
Returns
- CoordinateSequence
A deep copy of the sequence.
CreateCoordinateSequence(Coordinate[])
Convenience method which provides standard way of
creating a CoordinateSequence
.
protected virtual CoordinateSequence CreateCoordinateSequence(Coordinate[] coords)
Parameters
coords
Coordinate[]The coordinate array to copy.
Returns
- CoordinateSequence
A coordinate sequence for the array.
Transform(Geometry)
public Geometry Transform(Geometry inputGeom)
Parameters
inputGeom
Geometry
Returns
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.
protected virtual CoordinateSequence TransformCoordinates(CoordinateSequence coords, Geometry parent)
Parameters
coords
CoordinateSequenceThe coordinates to transform
parent
GeometryThe parent geometry
Returns
- CoordinateSequence
The transformed coordinates
TransformGeometryCollection(GeometryCollection, Geometry)
Transforms a GeometryCollection geometry.
protected virtual Geometry TransformGeometryCollection(GeometryCollection geom, Geometry parent)
Parameters
geom
GeometryCollectionThe
GeometryCollection
to transformparent
GeometryThe parent geometry
Returns
- Geometry
A
GeometryCollection
TransformLineString(LineString, Geometry)
Transforms a LineString geometry.
protected virtual Geometry TransformLineString(LineString geom, Geometry parent)
Parameters
geom
LineStringThe
LineString
to transformparent
GeometryThe parent geometry
Returns
- Geometry
A
LineString
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)
protected virtual Geometry TransformLinearRing(LinearRing geom, Geometry parent)
Parameters
geom
LinearRingThe
LinearRing
to transformparent
GeometryThe parent geometry
Returns
- Geometry
A
LinearRing
if the transformation resulted in a structurally valid ring, otherwise, if the transformation caused the LinearRing to collapse to 3 or fewer points, aLineString
TransformMultiLineString(MultiLineString, Geometry)
Transforms a MultiLineString geometry.
protected virtual Geometry TransformMultiLineString(MultiLineString geom, Geometry parent)
Parameters
geom
MultiLineStringThe
MultiLineString
to transformparent
GeometryThe parent geometry
Returns
- Geometry
A
MultiLineString
TransformMultiPoint(MultiPoint, Geometry)
Transforms a MultiPoint geometry.
protected virtual Geometry TransformMultiPoint(MultiPoint geom, Geometry parent)
Parameters
geom
MultiPointThe
MultiPoint
to transformparent
GeometryThe parent geometry
Returns
- Geometry
A
MultiPoint
TransformMultiPolygon(MultiPolygon, Geometry)
Transforms a MultiPolygon geometry.
protected virtual Geometry TransformMultiPolygon(MultiPolygon geom, Geometry parent)
Parameters
geom
MultiPolygonThe
MultiPolygon
to transformparent
GeometryThe parent geometry
Returns
- Geometry
A
MultiPolygon
TransformPoint(Point, Geometry)
Transforms a Point geometry.
protected virtual Geometry TransformPoint(Point geom, Geometry parent)
Parameters
Returns
- Geometry
A
Point
TransformPolygon(Polygon, Geometry)
Transforms a Polygon geometry.
protected virtual Geometry TransformPolygon(Polygon geom, Geometry parent)
Parameters
Returns
- Geometry
A
Polygon