Class GeometryFixer
java.lang.Object
org.locationtech.jts.geom.util.GeometryFixer
Fixes a geometry to be a valid geometry, while preserving as much as
possible of the shape and location of the input.
Validity is determined according to
Geometry.isValid().
Input geometries are always processed, so even valid inputs may have some minor alterations. The output is always a new geometry object.
Semantic Rules
- Vertices with non-finite X or Y ordinates are removed
(as per
Coordinate.isValid(). - Repeated points are reduced to a single point
- Empty atomic geometries are valid and are returned unchanged
- Empty elements are removed from collections
Point: keep valid coordinate, or EMPTYLineString: coordinates are fixedLinearRing: coordinates are fixed. Keep valid ring, or else convert intoLineStringPolygon: transform into a valid polygon or multipolygon, preserving as much of the extent and vertices as possible.- Rings are fixed to ensure they are valid
- Holes intersecting the shell are subtracted from the shell
- Holes outside the shell are converted into polygons
MultiPolygon: each polygon is fixed, then result made non-overlapping (via union)GeometryCollection: each element is fixed- Collapsed lines and polygons are handled as follows,
depending on the
keepCollapsedsetting:false: (default) collapses are converted to empty geometries (and removed if they are elements of collections)true: collapses are converted to a valid geometry of lower dimension
- Author:
- Martin Davis
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGeometryFixer(Geometry geom) Creates a new instance to fix a given geometry. -
Method Summary
Modifier and TypeMethodDescriptionstatic GeometryFixes a geometry to be valid.static GeometryFixes a geometry to be valid, allowing to set a flag controlling how single item results from fixedMULTIgeometries should be returned.Gets the fixed geometry.voidsetKeepCollapsed(boolean isKeepCollapsed) Sets whether collapsed geometries are converted to empty, (which will be removed from collections), or to a valid geometry of lower dimension.voidsetKeepMulti(boolean isKeepMulti) Sets whether fixedMULTIgeometries that consist of only one item should still be returned asMULTIgeometries.
-
Constructor Details
-
GeometryFixer
Creates a new instance to fix a given geometry.- Parameters:
geom- the geometry to be fixed
-
-
Method Details
-
fix
-
fix
Fixes a geometry to be valid, allowing to set a flag controlling how single item results from fixedMULTIgeometries should be returned.- Parameters:
geom- the geometry to be fixedisKeepMulti- a flag indicating ifMULTIgeometries should not be converted to single instance types if they consist of only one item.- Returns:
- the valid fixed geometry
-
setKeepCollapsed
public void setKeepCollapsed(boolean isKeepCollapsed) Sets whether collapsed geometries are converted to empty, (which will be removed from collections), or to a valid geometry of lower dimension. The default is to convert collapses to empty geometries.- Parameters:
isKeepCollapsed- whether collapses should be converted to a lower dimension geometry
-
setKeepMulti
public void setKeepMulti(boolean isKeepMulti) Sets whether fixedMULTIgeometries that consist of only one item should still be returned asMULTIgeometries. The default is to keepMULTIgeometries.- Parameters:
isKeepMulti- flag whether to keepMULTIgeometries.
-
getResult
-