Class GeometryFixer


  • public class GeometryFixer
    extends java.lang.Object
    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

    1. Vertices with non-finite X or Y ordinates are removed (as per Coordinate.isValid().
    2. Repeated points are reduced to a single point
    3. Empty atomic geometries are valid and are returned unchanged
    4. Empty elements are removed from collections
    5. Point: keep valid coordinate, or EMPTY
    6. LineString: fix coordinate list
    7. LinearRing: fix coordinate list, return as valid ring or else LineString
    8. Polygon: transform into a valid polygon, preserving as much of the extent and vertices as possible
    9. MultiPolygon: fix each polygon, then ensure result is non-overlapping (via union)
    10. GeometryCollection: fix each element
    11. Collapsed lines and polygons are handled as follows, depending on the keepCollapsed setting:
      • false: (default) collapses are converted to empty geometries
      • true: collapses are converted to a valid geometry of lower dimension
    Author:
    Martin Davis
    See Also:
    Geometry.isValid()
    • Constructor Summary

      Constructors 
      Constructor Description
      GeometryFixer​(Geometry geom)
      Creates a new instance to fix a given geometry.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Geometry fix​(Geometry geom)
      Fixes a geometry to be valid.
      Geometry getResult()
      Gets the fixed geometry.
      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.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GeometryFixer

        public GeometryFixer​(Geometry geom)
        Creates a new instance to fix a given geometry.
        Parameters:
        geom - the geometry to be fixed
    • Method Detail

      • fix

        public static Geometry fix​(Geometry geom)
        Fixes a geometry to be valid.
        Parameters:
        geom - the geometry to be fixed
        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
      • getResult

        public Geometry getResult()
        Gets the fixed geometry.
        Returns:
        the fixed geometry