Class GeometryPrecisionReducer
- Namespace
- NetTopologySuite.Precision
- Assembly
- NetTopologySuite.dll
Reduces the precision of a Geometry according to the supplied PrecisionModel, ensuring that the result is valid (unless specified otherwise).
By default the geometry precision model is not changed. This can be overridden by using ChangePrecisionModel.Topological Precision Reduction
The default mode of operation ensures the reduced result is topologically valid (i.e. IsValid is true). To ensure this polygonal geometry is reduced in a topologically valid fashion (technically, by using snap-rounding). Note that this may change polygonal geometry structure (e.g.two polygons separated by a distance below the specified precision will be merged into a single polygon). Duplicate vertices are removed. This mode is invoked by the static method Reduce(Geometry, PrecisionModel). Normally, collapsed linear components(e.g.lines collapsing to a point) are not included in the result. This behavior can be changed by setting RemoveCollapsedComponents tofalse
,
or by using the static method ReduceKeepCollapsed(Geometry, PrecisionModel).
In general input must be valid geometry, or an ArgumentException
will be thrown. However if the invalidity is "mild" or very small then it
may be eliminated by precision reduction.
Pointwise Precision Reduction
Alternatively, geometry can be reduced pointwise by using {@link #setPointwise(boolean)}. Linear and point geometry are always reduced pointwise(i.e.without further change to topology or structure), since this does not change validity. Invalid inputs are allowed. Duplicate vertices are preserved. Collapsed components are always included in the result. The result geometry may be invalid. This mode is invoked by the static method ReducePointwise(Geometry, PrecisionModel).public class GeometryPrecisionReducer
- Inheritance
-
GeometryPrecisionReducer
- Inherited Members
Constructors
GeometryPrecisionReducer(PrecisionModel)
public GeometryPrecisionReducer(PrecisionModel pm)
Parameters
Properties
ChangePrecisionModel
Gets or sets whether the PrecisionModel of the new reduced Geometry will be changed to be the PrecisionModel supplied to specify the precision reduction.
The default is to not change the precision modelpublic bool ChangePrecisionModel { get; set; }
Property Value
Pointwise
Gets or sets whether the precision reduction will be done in pointwise fashion only. Pointwise precision reduction reduces the precision of the individual coordinates only, but does not attempt to recreate valid topology. This is only relevant for geometries containing polygonal components.
public bool Pointwise { get; set; }
Property Value
RemoveCollapsedComponents
Gets or sets whether the reduction will result in collapsed components being removed completely, or simply being collapsed to an (invalid) Geometry of the same type. The default is to remove collapsed components.
public bool RemoveCollapsedComponents { get; set; }
Property Value
Methods
Reduce(Geometry)
Reduces the precision of a geometry, according to the specified strategy of this reducer.
public Geometry Reduce(Geometry geom)
Parameters
geom
GeometryThe geometry to reduce
Returns
- Geometry
The precision-reduced geometry
Exceptions
- ArgumentException
if the reduction fails due to input geometry is invalid.
Reduce(Geometry, PrecisionModel)
Reduces precision of a geometry, ensuring output geometry is valid. Collapsed linear and polygonal components are removed. The geometry precision model is not changed. Invalid input geometry may cause an error, unless the invalidity is below the scale of the precision reduction.
public static Geometry Reduce(Geometry g, PrecisionModel precModel)
Parameters
g
GeometryThe geometry to reduce
precModel
PrecisionModelThe precision model to use
Returns
- Geometry
The reduced geometry
Exceptions
- ArgumentException
Thrwon if the reduction fails due to invalid input geometry
ReduceKeepCollapsed(Geometry, PrecisionModel)
Reduces precision of a geometry, ensuring output polygonal geometry is valid, and preserving collapsed linear elements. The geometry precision model is not changed. Invalid input geometry may cause an error, unless the invalidity is below the scale of the precision reduction.
public static Geometry ReduceKeepCollapsed(Geometry geom, PrecisionModel pm)
Parameters
geom
Geometrypm
PrecisionModel
Returns
- Geometry
The reduced geometry
Exceptions
- ArgumentException
Thrwon if the reduction fails due to invalid input geometry
ReducePointwise(Geometry, PrecisionModel)
Reduce precision of a geometry in a pointwise way. All input geometry elements are preserved in the output, including invalid polygons and collapsed polygons and linestrings. The output may not be valid, due to collapse or self-intersection. The geometry precision model is not changed. Invalid input geometry is allowed.
public static Geometry ReducePointwise(Geometry g, PrecisionModel precModel)
Parameters
g
GeometryThe geometry to reduce
precModel
PrecisionModelThe precision model to use
Returns
- Geometry
The reduced geometry