Class GeometryPrecisionReducer
- java.lang.Object
-
- org.locationtech.jts.precision.GeometryPrecisionReducer
-
public class GeometryPrecisionReducer extends java.lang.Object
Reduces the precision of aGeometry
according to the suppliedPrecisionModel
, ensuring that the result is valid (unless specified otherwise).By default the geometry precision model is not changed. This can be overridden by using
setChangePrecisionModel(boolean)
.Topological Precision Reduction
The default mode of operation ensures the reduced result is topologically valid (i.e.Geometry.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 methodreduce(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
setRemoveCollapsedComponents(boolean)
tofalse
, or by using the static methodreduceKeepCollapsed(Geometry, PrecisionModel)
.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.Pointwise Precision Reduction
Alternatively, geometry can be reduced pointwise by usingsetPointwise(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)
.- Version:
- 1.12
-
-
Constructor Summary
Constructors Constructor Description GeometryPrecisionReducer(PrecisionModel pm)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Geometry
reduce(Geometry geom)
Reduces the precision of a geometry, according to the specified strategy of this reducer.static Geometry
reduce(Geometry g, PrecisionModel precModel)
Reduces precision of a geometry, ensuring output geometry is valid.static Geometry
reduceKeepCollapsed(Geometry geom, PrecisionModel pm)
Reduces precision of a geometry, ensuring output polygonal geometry is valid, and preserving collapsed linear elements.static Geometry
reducePointwise(Geometry g, PrecisionModel precModel)
Reduce precision of a geometry in a pointwise way.void
setChangePrecisionModel(boolean changePrecisionModel)
Sets whether thePrecisionModel
of the new reduced Geometry will be changed to be thePrecisionModel
supplied to specify the precision reduction.void
setPointwise(boolean isPointwise)
Sets whether the precision reduction will be done in pointwise fashion only.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.
-
-
-
Constructor Detail
-
GeometryPrecisionReducer
public GeometryPrecisionReducer(PrecisionModel pm)
-
-
Method Detail
-
reduce
public static Geometry reduce(Geometry g, PrecisionModel precModel)
Reduces precision of a geometry, ensuring output geometry is valid. Collapsed linear and polygonal components are removed. Duplicate vertices 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.
- Parameters:
g
- the geometry to reduceprecModel
- the precision model to use- Returns:
- the reduced geometry
- Throws:
java.lang.IllegalArgumentException
- if the reduction fails due to invalid input geometry
-
reduceKeepCollapsed
public static Geometry reduceKeepCollapsed(Geometry geom, PrecisionModel pm)
Reduces precision of a geometry, ensuring output polygonal geometry is valid, and preserving collapsed linear elements. Duplicate vertices 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.
- Parameters:
g
- the geometry to reduceprecModel
- the precision model to use- Returns:
- the reduced geometry
- Throws:
java.lang.IllegalArgumentException
- if the reduction fails due to invalid input geometry
-
reducePointwise
public static Geometry reducePointwise(Geometry g, PrecisionModel precModel)
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. Duplicate vertices are not removed. The geometry precision model is not changed.Invalid input geometry is allowed.
- 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
- iftrue
collapsed components will be removed
-
setChangePrecisionModel
public void setChangePrecisionModel(boolean changePrecisionModel)
Sets whether thePrecisionModel
of the new reduced Geometry will be changed to be thePrecisionModel
supplied to specify the precision reduction.The default is to not change the precision model
- Parameters:
changePrecisionModel
- iftrue
the 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
public Geometry reduce(Geometry geom)
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:
java.lang.IllegalArgumentException
- if the reduction fails due to invalid input geometry is invalid
-
-