Class GeometryPrecisionReducer
Geometry
according to the supplied PrecisionModel,
ensuring that the result is valid (unless specified otherwise).
By default the reduced result is topologically valid
(i.e. Geometry.isValid() is true).
To ensure this a 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).
In general input must be valid geometry, or an IllegalArgumentException
will be thrown. However if the invalidity is "mild" or very small then it
may be eliminated by precision reduction.
Alternatively, geometry can be reduced pointwise by using setPointwise(boolean).
In this case the result geometry topology may be invalid.
Linear and point geometry are always reduced pointwise (i.e. without further change to
topology or structure), since this does not change validity.
By default the geometry precision model is not changed.
This can be overridden by using setChangePrecisionModel(boolean).
Normally collapsed components (e.g. lines collapsing to a point)
are not included in the result.
This behavior can be changed by using setRemoveCollapsedComponents(boolean).
- Version:
- 1.12
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReduces the precision of a geometry, according to the specified strategy of this reducer.static Geometryreduce(Geometry g, PrecisionModel precModel) Convenience method for doing precision reduction on a single geometry, with collapses removed and keeping the geometry precision model the same, and preserving polygonal topology.static GeometryreducePointwise(Geometry g, PrecisionModel precModel) Convenience method for doing pointwise precision reduction on a single geometry, with collapses removed and keeping the geometry precision model the same, but NOT preserving valid polygonal topology.voidsetChangePrecisionModel(boolean changePrecisionModel) Sets whether thePrecisionModelof the new reduced Geometry will be changed to be thePrecisionModelsupplied to specify the precision reduction.voidsetPointwise(boolean isPointwise) Sets whether the precision reduction will be done in pointwise fashion only.voidsetRemoveCollapsedComponents(boolean removeCollapsed) Sets whether the reduction will result in collapsed components being removed completely, or simply being collapsed to an (invalid) Geometry of the same type.
-
Constructor Details
-
GeometryPrecisionReducer
-
-
Method Details
-
reduce
Convenience method for doing precision reduction on a single geometry, with collapses removed and keeping the geometry precision model the same, and preserving polygonal topology.- Parameters:
g- the geometry to reduceprecModel- the precision model to use- Returns:
- the reduced geometry
- Throws:
IllegalArgumentException- if the reduction fails due to invalid input geometry is invalid
-
reducePointwise
Convenience method for doing pointwise precision reduction on a single geometry, with collapses removed and keeping the geometry precision model the same, but NOT preserving valid polygonal topology.- Parameters:
g- the geometry to reduceprecModel- the precision model to use- Returns:
- the reduced geometry
-
setRemoveCollapsedComponents
public void setRemoveCollapsedComponents(boolean removeCollapsed) 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.- Parameters:
removeCollapsed- iftruecollapsed components will be removed
-
setChangePrecisionModel
public void setChangePrecisionModel(boolean changePrecisionModel) Sets whether thePrecisionModelof the new reduced Geometry will be changed to be thePrecisionModelsupplied to specify the precision reduction.The default is to not change the precision model
- Parameters:
changePrecisionModel- iftruethe precision model of the created Geometry will be the the precisionModel supplied in the constructor.
-
setPointwise
public void setPointwise(boolean isPointwise) 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.- Parameters:
isPointwise- if reduction should be done pointwise only
-
reduce
Reduces the precision of a geometry, according to the specified strategy of this reducer.- Parameters:
geom- the geometry to reduce- Returns:
- the precision-reduced geometry
- Throws:
IllegalArgumentException- if the reduction fails due to invalid input geometry is invalid
-