Class Grids


  • public class Grids
    extends Object
    A utility class to create polygonal vector grids with basic attributes. For simple grids this is the only class you need. For finer control of grid attributes, such as working with a user-supplied SimpleFeatureType, see the Oblongs and Hexagons utility classes.
    Since:
    2.7
    Author:
    mbedward
    • Constructor Detail

      • Grids

        public Grids()
    • Method Detail

      • createSquareGrid

        public static SimpleFeatureSource createSquareGrid​(ReferencedEnvelope bounds,
                                                           double sideLen)
        Creates a vector grid of square elements. The coordinate reference system is taken from the input bounds. A null coordinate reference system is permitted.

        The grid's origin is the minimum X and Y point of the envelope. If the width and/or height of the bounding envelope is not a simple multiple of the requested side length, there will be some unfilled space.

        Each square in the returned grid is represented by a SimpleFeature. The feature type has two properties:

        • element - type Polygon
        • id - type Integer
        Parameters:
        bounds - bounds of the grid
        sideLen - the side length of grid elements
        Returns:
        the vector grid
        Throws:
        IllegalArgumentException - if bounds is null or empty; or if sideLen is <= 0
      • createSquareGrid

        public static SimpleFeatureSource createSquareGrid​(ReferencedEnvelope bounds,
                                                           double sideLen,
                                                           double vertexSpacing)
        Creates a vector grid of square elements represented by 'densified' polygons. Each polygon has additional vertices added to its edges. This is useful if you plan to display the grid in a projection other than the one that it was created in since the extra vertices will better approximate curves. The density of vertices is controlled by the value of vertexSpacing which specifies the maximum distance between adjacent vertices. Vertices are added more or less uniformly.

        The coordinate reference system is taken from the input bounds. A null coordinate reference system is permitted.

        The grid's origin is the minimum X and Y point of the envelope. If the width and/or height of the bounding envelope is not a simple multiple of the requested side length, there will be some unfilled space.

        Each square in the returned grid is represented by a SimpleFeature. The feature type has two properties:

        • element - type Polygon
        • id - type Integer
        Parameters:
        bounds - bounds of the grid
        sideLen - the side length of grid elements
        vertexSpacing - maximum distance between adjacent vertices in a grid element; if <= 0 or >= sideLen / 2.0 it is ignored and the polygons will not be densified
        Returns:
        the vector grid
        Throws:
        IllegalArgumentException - if bounds is null or empty; or if sideLen is <= 0
      • createSquareGrid

        public static SimpleFeatureSource createSquareGrid​(ReferencedEnvelope bounds,
                                                           double sideLen,
                                                           double vertexSpacing,
                                                           GridFeatureBuilder builder)
        Creates a vector grid of square elements represented by 'densified' polygons. Each polygon has additional vertices added to its edges. This is useful if you plan to display the grid in a projection other than the one that it was created in since the extra vertices will better approximate curves. The density of vertices is controlled by the value of vertexSpacing which specifies the maximum distance between adjacent vertices. Vertices are added more or less uniformly.

        The coordinate reference system is taken from the GridFeatureBuilder. A null coordinate reference system is permitted but if both the builder and bounding envelope have non-null reference systems set they must be the same.

        The grid's origin is the minimum X and Y point of the envelope. If the width and/or height of the bounding envelope is not a simple multiple of the requested side length, there will be some unfilled space.

        Parameters:
        bounds - bounds of the grid
        sideLen - the side length of grid elements
        vertexSpacing - maximum distance between adjacent vertices in a grid element; if <= 0 or >= sideLen / 2.0 the polygons will not be densified
        builder - the GridFeatureBuilder used to control feature creation and the setting of feature attribute values
        Returns:
        the vector grid
        Throws:
        IllegalArgumentException - if bounds is null or empty; or if sideLen is <= 0; or if builder is null; or if the CoordinateReferenceSystems set for the bounds and the GridFeatureBuilder are both non-null but different
      • createHexagonalGrid

        public static SimpleFeatureSource createHexagonalGrid​(ReferencedEnvelope bounds,
                                                              double sideLen)
        Creates a vector grid of hexagonal elements. Hexagon size is expressed as side length. To create hexagons of specified area you can use the static Hexagons.areaToSideLength(double) method to calculate the equivalent side length.

        The hexagons created by this method are orientated with a pair of edges parallel to the top and bottom of the bounding envelope (org.geotools.grid.hexagon.Hexagon.Orientation#FLAT). The bounding rectangle of each hexagon has width sideLen * 2.0 and height sideLen * sqrt(3.0).

        The grid's origin is the minimum X and Y point of the envelope.

        The feature type of grid features has two properties:

        • element - type Polygon
        • id - type Integer
        Parameters:
        bounds - bounds of the grid
        sideLen - the length
        Returns:
        the vector grid
        Throws:
        IllegalArgumentException - if bounds is null or empty; or if sideLen is <= 0
      • createHexagonalGrid

        public static SimpleFeatureSource createHexagonalGrid​(ReferencedEnvelope bounds,
                                                              double sideLen,
                                                              double vertexSpacing)
        Creates a vector grid of hexagonal elements represented by 'densified' polygons. Each polygon has additional vertices added to its edges. This is useful if you plan to display the grid in a projection other than the one that it was created in since the extra vertices will better approximate curves. The density of vertices is controlled by the value of vertexSpacing which specifies the maximum distance between adjacent vertices. Vertices are added more or less uniformly.

        Hexagon size is expressed as side length. To create hexagons of specified area you can use the static Hexagons.areaToSideLength(double) method to calculate the equivalent side length.

        The hexagons created by this method are orientated with a pair of edges parallel to the top and bottom of the bounding envelope (org.geotools.grid.hexagon.Hexagon.Orientation#FLAT). The bounding rectangle of each hexagon has width sideLen * 2.0 and height sideLen * sqrt(3.0).

        The grid's origin is the minimum X and Y point of the envelope.

        The feature type of grid features has two properties:

        • element - type Polygon
        • id - type Integer
        Parameters:
        bounds - bounds of the grid
        sideLen - the length
        vertexSpacing - maximum distance between adjacent vertices in a grid element; if <= 0 or >= sideLen / 2.0 the polygons will not be densified
        Returns:
        the vector grid
        Throws:
        IllegalArgumentException - if bounds is null or empty; or if sideLen is <= 0
      • createHexagonalGrid

        public static SimpleFeatureSource createHexagonalGrid​(ReferencedEnvelope bounds,
                                                              double sideLen,
                                                              double vertexSpacing,
                                                              GridFeatureBuilder builder)
        Creates a vector grid of hexagonal elements represented by 'densified' polygons. Each polygon has additional vertices added to its edges. This is useful if you plan to display the grid in a projection other than the one that it was created in since the extra vertices will better approximate curves. The density of vertices is controlled by the value of vertexSpacing which specifies the maximum distance between adjacent vertices. Vertices are added more or less uniformly.

        Hexagon size is expressed as side length. To create hexagons of specified area you can use the static Hexagons.areaToSideLength(double) method to calculate the equivalent side length.

        The hexagons created by this method are orientated with a pair of edges parallel to the top and bottom of the bounding envelope (org.geotools.grid.hexagon.Hexagon.Orientation#FLAT). The bounding rectangle of each hexagon has width sideLen * 2.0 and height sideLen * sqrt(3.0).

        The grid's origin is the minimum X and Y point of the envelope.

        The feature type of grid features has two properties:

        • element - type Polygon
        • id - type Integer
        Parameters:
        bounds - bounds of the grid
        sideLen - the length
        vertexSpacing - maximum distance between adjacent vertices in a grid element; if <= 0 or >= sideLen / 2.0 the polygons will not be densified
        builder - the GridFeatureBuilder used to control feature creation and the setting of feature attribute values
        Returns:
        the vector grid
        Throws:
        IllegalArgumentException - if bounds is null or empty; or if sideLen is <= 0; or if builder is null; or if the CoordinateReferenceSystems set for the bounds and the GridFeatureBuilder are both non-null but different
      • createOvalGrid

        public static SimpleFeatureSource createOvalGrid​(ReferencedEnvelope bounds,
                                                         double sideLen)
        Creates a vector grid of oval elements. The coordinate reference system is taken from the input bounds. A null coordinate reference system is permitted.

        The grid's origin is the minimum X and Y point of the envelope. If the width and/or height of the bounding envelope is not a simple multiple of the requested side length, there will be some unfilled space.

        Each oval in the returned grid is represented by a SimpleFeature. The feature type has two properties:

        • element - type Polygon
        • id - type Integer
        Parameters:
        bounds - bounds of the grid
        sideLen - the side length of grid elements
        Returns:
        the vector grid
        Throws:
        IllegalArgumentException - if bounds is null or empty; or if sideLen is <= 0
      • createOvalGrid

        public static SimpleFeatureSource createOvalGrid​(ReferencedEnvelope bounds,
                                                         double sideLen,
                                                         GridFeatureBuilder builder)
        Creates a vector grid of square elements represented by 'densified' polygons. Each polygon has additional vertices added to its edges. This is useful if you plan to display the grid in a projection other than the one that it was created in since the extra vertices will better approximate curves. The density of vertices is controlled by the value of vertexSpacing which specifies the maximum distance between adjacent vertices. Vertices are added more or less uniformly.

        The coordinate reference system is taken from the GridFeatureBuilder. A null coordinate reference system is permitted but if both the builder and bounding envelope have non-null reference systems set they must be the same.

        The grid's origin is the minimum X and Y point of the envelope. If the width and/or height of the bounding envelope is not a simple multiple of the requested side length, there will be some unfilled space.

        Parameters:
        bounds - bounds of the grid
        sideLen - the side length of grid elements
        builder - the GridFeatureBuilder used to control feature creation and the setting of feature attribute values
        Returns:
        the vector grid
        Throws:
        IllegalArgumentException - if bounds is null or empty; or if sideLen is <= 0; or if builder is null; or if the CoordinateReferenceSystems set for the bounds and the GridFeatureBuilder are both non-null but different