Class CoverageValidator

java.lang.Object
org.locationtech.jts.coverage.CoverageValidator

public class CoverageValidator extends Object
Validates a polygonal coverage, and returns the locations of invalid polygon boundary segments if found.

A polygonal coverage is a set of polygons which may be edge-adjacent but do not overlap. Coverage algorithms (such as CoverageUnion or simplification) generally require the input coverage to be valid to produce correct results. A polygonal coverage is valid if:

  1. The interiors of all polygons do not intersect (are disjoint). This is the case if no polygon has a boundary which intersects the interior of another polygon, and no two polygons are identical.
  2. If the boundaries of polygons intersect, the vertices and line segments of the intersection match exactly.

A valid coverage may contain holes (regions of no coverage). Sometimes it is desired to detect whether coverages contain narrow gaps between polygons (which can be a result of digitizing error or misaligned data). This class can detect narrow gaps, by specifying a maximum gap width using setGapWidth(double). Note that this also identifies narrow gaps separating disjoint coverage regions, and narrow gores. In some situations it may also produce false positives (linework identified as part of a gap which is actually wider). See CoverageGapFinder for an alternate way to detect gaps which may be more accurate.

Author:
Martin Davis
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new coverage validator
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    hasInvalidResult(Geometry[] validateResult)
    Tests if some element of an array of geometries is a coverage invalidity indicator.
    static boolean
    isValid(Geometry[] coverage)
    Tests whether a polygonal coverage is valid.
    void
    setGapWidth(double gapWidth)
    Sets the maximum gap width, if narrow gaps are to be detected.
    Validates the polygonal coverage.
    static Geometry[]
    validate(Geometry[] coverage)
    Validates that a set of polygons forms a valid polygonal coverage, and returns linear geometries indicating the locations of invalidities, if any.
    static Geometry[]
    validate(Geometry[] coverage, double gapWidth)
    Validates that a set of polygons forms a valid polygonal coverage and contains no gaps narrower than a specified width.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CoverageValidator

      public CoverageValidator(Geometry[] coverage)
      Creates a new coverage validator
      Parameters:
      coverage - a array of polygons representing a polygonal coverage
  • Method Details

    • isValid

      public static boolean isValid(Geometry[] coverage)
      Tests whether a polygonal coverage is valid.
      Parameters:
      coverage - an array of polygons forming a coverage
      Returns:
      true if the coverage is valid
    • hasInvalidResult

      public static boolean hasInvalidResult(Geometry[] validateResult)
      Tests if some element of an array of geometries is a coverage invalidity indicator.
      Parameters:
      validateResult - an array produced by a polygonal coverage validation
      Returns:
      true if the result has at least one invalid indicator
    • validate

      public static Geometry[] validate(Geometry[] coverage)
      Validates that a set of polygons forms a valid polygonal coverage, and returns linear geometries indicating the locations of invalidities, if any.
      Parameters:
      coverage - an array of polygons forming a coverage
      Returns:
      an array of linear geometries indicating coverage errors, or nulls
    • validate

      public static Geometry[] validate(Geometry[] coverage, double gapWidth)
      Validates that a set of polygons forms a valid polygonal coverage and contains no gaps narrower than a specified width. The result is an array of linear geometries indicating the locations of invalidities, or null if the polygon is coverage-valid.
      Parameters:
      coverage - an array of polygons forming a coverage
      gapWidth - the maximum width of invalid gaps
      Returns:
      an array of linear geometries indicating coverage errors, or nulls
    • setGapWidth

      public void setGapWidth(double gapWidth)
      Sets the maximum gap width, if narrow gaps are to be detected.
      Parameters:
      gapWidth - the maximum width of gaps to detect
    • validate

      public Geometry[] validate()
      Validates the polygonal coverage. The result is an array of the same size as the input coverage. Each array entry is either null, or if the polygon does not form a valid coverage, a linear geometry containing the boundary segments which intersect polygon interiors, which are mismatched, or form gaps (if checked).
      Returns:
      an array of nulls or linear geometries