Class IsValidOp

java.lang.Object
org.locationtech.jts.operation.valid.IsValidOp

public class IsValidOp extends Object
Implements the algorithms required to compute the isValid() method for Geometrys. See the documentation for the various geometry types for a specification of validity.
Version:
1.7
  • Field Details

    • parentGeometry

      private Geometry parentGeometry
    • isSelfTouchingRingFormingHoleValid

      private boolean isSelfTouchingRingFormingHoleValid
      If the following condition is TRUE JTS will validate inverted shells and exverted holes (the ESRI SDE model)
    • validErr

      private TopologyValidationError validErr
  • Constructor Details

    • IsValidOp

      public IsValidOp(Geometry parentGeometry)
  • Method Details

    • isValid

      public static boolean isValid(Geometry geom)
      Tests whether a Geometry is valid.
      Parameters:
      geom - the Geometry to test
      Returns:
      true if the geometry is valid
    • isValid

      public static boolean isValid(Coordinate coord)
      Checks whether a coordinate is valid for processing. Coordinates are valid iff their x and y ordinates are in the range of the floating point representation.
      Parameters:
      coord - the coordinate to validate
      Returns:
      true if the coordinate is valid
    • findPtNotNode

      public static Coordinate findPtNotNode(Coordinate[] testCoords, LinearRing searchRing, GeometryGraph graph)
      Find a point from the list of testCoords that is NOT a node in the edge for the list of searchCoords
      Returns:
      the point found, or null if none found
    • setSelfTouchingRingFormingHoleValid

      public void setSelfTouchingRingFormingHoleValid(boolean isValid)
      Sets whether polygons using Self-Touching Rings to form holes are reported as valid. If this flag is set, the following Self-Touching conditions are treated as being valid:
      • the shell ring self-touches to create a hole touching the shell
      • a hole ring self-touches to create two holes touching at a point

      The default (following the OGC SFS standard) is that this condition is not valid (false).

      This does not affect whether Self-Touching Rings disconnecting the polygon interior are considered valid (these are considered to be invalid under the SFS, and many other spatial models as well). This includes "bow-tie" shells, which self-touch at a single point causing the interior to be disconnected, and "C-shaped" holes which self-touch at a single point causing an island to be formed.

      Parameters:
      isValid - states whether geometry with this condition is valid
    • isValid

      public boolean isValid()
      Computes the validity of the geometry, and returns true if it is valid.
      Returns:
      true if the geometry is valid
    • getValidationError

      public TopologyValidationError getValidationError()
      Computes the validity of the geometry, and if not valid returns the validation error for the geometry, or null if the geometry is valid.
      Returns:
      the validation error, if the geometry is invalid or null if the geometry is valid
    • checkValid

      private void checkValid(Geometry g)
    • checkValid

      private void checkValid(Point g)
      Checks validity of a Point.
    • checkValid

      private void checkValid(MultiPoint g)
      Checks validity of a MultiPoint.
    • checkValid

      private void checkValid(LineString g)
      Checks validity of a LineString. Almost anything goes for linestrings!
    • checkValid

      private void checkValid(LinearRing g)
      Checks validity of a LinearRing.
    • checkValid

      private void checkValid(Polygon g)
      Checks the validity of a polygon. Sets the validErr flag.
    • checkValid

      private void checkValid(MultiPolygon g)
    • checkValid

      private void checkValid(GeometryCollection gc)
    • checkInvalidCoordinates

      private void checkInvalidCoordinates(Coordinate[] coords)
    • checkInvalidCoordinates

      private void checkInvalidCoordinates(Polygon poly)
    • checkClosedRings

      private void checkClosedRings(Polygon poly)
    • checkClosedRing

      private void checkClosedRing(LinearRing ring)
    • checkTooFewPoints

      private void checkTooFewPoints(GeometryGraph graph)
    • checkConsistentArea

      private void checkConsistentArea(GeometryGraph graph)
      Checks that the arrangement of edges in a polygonal geometry graph forms a consistent area.
      Parameters:
      graph -
      See Also:
    • checkNoSelfIntersectingRings

      private void checkNoSelfIntersectingRings(GeometryGraph graph)
      Check that there is no ring which self-intersects (except of course at its endpoints). This is required by OGC topology rules (but not by other models such as ESRI SDE, which allow inverted shells and exverted holes).
      Parameters:
      graph - the topology graph of the geometry
    • checkNoSelfIntersectingRing

      private void checkNoSelfIntersectingRing(EdgeIntersectionList eiList)
      Check that a ring does not self-intersect, except at its endpoints. Algorithm is to count the number of times each node along edge occurs. If any occur more than once, that must be a self-intersection.
    • checkHolesInShell

      private void checkHolesInShell(Polygon p, GeometryGraph graph)
      Tests that each hole is inside the polygon shell. This routine assumes that the holes have previously been tested to ensure that all vertices lie on the shell or on the same side of it (i.e. that the hole rings do not cross the shell ring). In other words, this test is only correct if the ConsistentArea test is passed first. Given this, a simple point-in-polygon test of a single point in the hole can be used, provided the point is chosen such that it does not lie on the shell.
      Parameters:
      p - the polygon to be tested for hole inclusion
      graph - a GeometryGraph incorporating the polygon
    • checkHolesNotNested

      private void checkHolesNotNested(Polygon p, GeometryGraph graph)
      Tests that no hole is nested inside another hole. This routine assumes that the holes are disjoint. To ensure this, holes have previously been tested to ensure that:
      • they do not partially overlap (checked by checkRelateConsistency)
      • they are not identical (checked by checkRelateConsistency)
    • checkShellsNotNested

      private void checkShellsNotNested(MultiPolygon mp, GeometryGraph graph)
      Tests that no element polygon is wholly in the interior of another element polygon.

      Preconditions:

      • shells do not partially overlap
      • shells do not touch along an edge
      • no duplicate rings exist
      This routine relies on the fact that while polygon shells may touch at one or more vertices, they cannot touch at ALL vertices.
    • checkShellNotNested

      private void checkShellNotNested(LinearRing shell, Polygon p, GeometryGraph graph)
      Check if a shell is incorrectly nested within a polygon. This is the case if the shell is inside the polygon shell, but not inside a polygon hole. (If the shell is inside a polygon hole, the nesting is valid.)

      The algorithm used relies on the fact that the rings must be properly contained. E.g. they cannot partially overlap (this has been previously checked by checkRelateConsistency )

    • checkShellInsideHole

      private Coordinate checkShellInsideHole(LinearRing shell, LinearRing hole, GeometryGraph graph)
      This routine checks to see if a shell is properly contained in a hole. It assumes that the edges of the shell and hole do not properly intersect.
      Returns:
      null if the shell is properly contained, or a Coordinate which is not inside the hole if it is not
    • checkConnectedInteriors

      private void checkConnectedInteriors(GeometryGraph graph)