Class MarchingSquaresVectorizer


  • public final class MarchingSquaresVectorizer
    extends Object
    Algorithm computing the image footprint. Some optimizations are made. When running along the image perimeter, whenever a closed polygon is found, the inner area is filled to make sure we won't analyze that.

    It can deal with GridCoverage2D instances, returning footprint in real world coordinates, as well as with RenderedImage instances, returning footprint in raster space coordinates

    Author:
    Daniele Romagnoli, GeoSolutions SAS, Simone Giannecchini, GeoSolutions SAS, Andrea Aime, GeoSolutions SAS
    • Field Detail

      • DEFAULT_RANGES

        public static final List<Range<Integer>> DEFAULT_RANGES
      • DEFAULT_SIMPLIFIER_FACTOR

        public static final double DEFAULT_SIMPLIFIER_FACTOR
        See Also:
        Constant Field Values
      • DEFAULT_THRESHOLD_AREA

        public static final double DEFAULT_THRESHOLD_AREA
        See Also:
        Constant Field Values
    • Constructor Detail

      • MarchingSquaresVectorizer

        public MarchingSquaresVectorizer​(GridCoverage2D inGeodata,
                                         RenderingHints hints,
                                         double thresholdArea,
                                         double simplifierFactor,
                                         MarchingSquaresVectorizer.ImageLoadingType imageLoadingType,
                                         List<Range<Integer>> exclusionLuminanceRanges)
        Main Constructor using GridCoverage2D as input.
        Parameters:
        inGeodata - the input GridCoverage2D
        hints - hints to be used by inner processing, it usually contains tile caches, schedulers
        thresholdArea - the minimum area required by a polygon to be included in the result
        simplifierFactor - the simplifier factor to be applied to compute the simplified version of the biggest polygon.
        imageLoadingType - the type of imageLoading (DEFERRED vs IMMEDIATE).
        exclusionLuminanceRanges - the ranges of luminance values to be excluded by the computation.
      • MarchingSquaresVectorizer

        public MarchingSquaresVectorizer​(RenderedImage ri,
                                         RenderingHints hints,
                                         double thresholdArea,
                                         MarchingSquaresVectorizer.ImageLoadingType imageLoadingType,
                                         List<Range<Integer>> exclusionLuminanceRanges)
        Main Constructor using RenderedImage as input. Returned footprint coordinates will be in raster space.
        Parameters:
        ri - the input RenderedImage
        hints - hints to be used by inner processing, it usually contains tile caches, schedulers
        thresholdArea - the minimum area required by a polygon to be included in the result
        imageLoadingType - the type of imageLoading (DEFERRED vs IMMEDIATE).
        exclusionLuminanceRanges - the range of luminance values to be excluded by the computation.
      • MarchingSquaresVectorizer

        public MarchingSquaresVectorizer()
    • Method Detail

      • getRoiShape

        public ROIShape getRoiShape()
        Return the ROIShape version of the footprint after computation
      • getPolygonArea

        public double getPolygonArea()
        Return the area of the simplified footprint after computation
      • getSimplifiedFootprint

        public Geometry getSimplifiedFootprint()
        Return the simplified footprint
      • getFootprint

        public Geometry getFootprint()
        Return the precise footprint
      • setRemoveCollinear

        public void setRemoveCollinear​(boolean removeCollinear)
        When set to true (the default) will perform collinear vertices removal
      • setForceValid

        public void setForceValid​(boolean forceValid)
        When set to true (the default) will perform extra checks on the output polygons to make sure they are valid geometries
      • setComputeSimplifiedFootprint

        public void setComputeSimplifiedFootprint​(boolean computeSimplifiedFootprint)
        When set to true, a simplified version of the footprint will be returned too
      • process

        public void process()
                     throws Exception
        Executes the MarchingSquares algorithm to find the footprint.
        Throws:
        Exception
      • areEqual

        public static final boolean areEqual​(double value,
                                             double pValue)
        Simple check returning where two double values are equal
      • dispose

        public void dispose()
      • getPolygonArea

        public static double getPolygonArea​(List<Coordinate> coordinateList)
        Calculates the area of a polygon from the coordinates.
        Returns:
        the area of the polygon.
      • getPolygonArea

        public static double getPolygonArea​(int[] x,
                                            int[] y,
                                            int N)
        Calculates the area of a polygon from its vertices.
        Parameters:
        x - the array of x coordinates.
        y - the array of y coordinates.
        N - the number of sides of the polygon.
        Returns:
        the area of the polygon.
      • createSimplePolygon

        public static Polygon createSimplePolygon​(Coordinate[] coords)
        Create a simple polygon (no holes).
        Parameters:
        coords - the coords of the polygon.
        Returns:
        the Polygon.