Class Grids
 Object

 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 usersupplied SimpleFeatureType, see theOblongs
andHexagons
utility classes. Since:
 2.7
 Author:
 mbedward


Constructor Summary
Constructors Constructor Description Grids()

Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SimpleFeatureSource
createHexagonalGrid(ReferencedEnvelope bounds, double sideLen)
Creates a vector grid of hexagonal elements.static SimpleFeatureSource
createHexagonalGrid(ReferencedEnvelope bounds, double sideLen, double vertexSpacing)
Creates a vector grid of hexagonal elements represented by 'densified' polygons.static SimpleFeatureSource
createHexagonalGrid(ReferencedEnvelope bounds, double sideLen, double vertexSpacing, GridFeatureBuilder builder)
Creates a vector grid of hexagonal elements represented by 'densified' polygons.static SimpleFeatureSource
createOvalGrid(ReferencedEnvelope bounds, double sideLen)
Creates a vector grid of oval elements.static SimpleFeatureSource
createOvalGrid(ReferencedEnvelope bounds, double sideLen, GridFeatureBuilder builder)
Creates a vector grid of square elements represented by 'densified' polygons.static SimpleFeatureSource
createSquareGrid(ReferencedEnvelope bounds, double sideLen)
Creates a vector grid of square elements.static SimpleFeatureSource
createSquareGrid(ReferencedEnvelope bounds, double sideLen, double vertexSpacing)
Creates a vector grid of square elements represented by 'densified' polygons.static SimpleFeatureSource
createSquareGrid(ReferencedEnvelope bounds, double sideLen, double vertexSpacing, GridFeatureBuilder builder)
Creates a vector grid of square elements represented by 'densified' polygons.



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. Anull
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 gridsideLen
 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 ofvertexSpacing
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 gridsideLen
 the side length of grid elementsvertexSpacing
 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 ofvertexSpacing
which specifies the maximum distance between adjacent vertices. Vertices are added more or less uniformly.The coordinate reference system is taken from the
GridFeatureBuilder
. Anull
coordinate reference system is permitted but if both the builder and bounding envelope have nonnull
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 gridsideLen
 the side length of grid elementsvertexSpacing
 maximum distance between adjacent vertices in a grid element; if<= 0
or>= sideLen / 2.0
the polygons will not be densifiedbuilder
 theGridFeatureBuilder
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 theCoordinateReferenceSystems
set for the bounds and theGridFeatureBuilder
are both nonnull 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 heightsideLen * 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 gridsideLen
 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 ofvertexSpacing
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 heightsideLen * 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 gridsideLen
 the lengthvertexSpacing
 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 ofvertexSpacing
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 heightsideLen * 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 gridsideLen
 the lengthvertexSpacing
 maximum distance between adjacent vertices in a grid element; if<= 0
or>= sideLen / 2.0
the polygons will not be densifiedbuilder
 theGridFeatureBuilder
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 theCoordinateReferenceSystems
set for the bounds and theGridFeatureBuilder
are both nonnull 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. Anull
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 gridsideLen
 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 ofvertexSpacing
which specifies the maximum distance between adjacent vertices. Vertices are added more or less uniformly.The coordinate reference system is taken from the
GridFeatureBuilder
. Anull
coordinate reference system is permitted but if both the builder and bounding envelope have nonnull
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 gridsideLen
 the side length of grid elementsbuilder
 theGridFeatureBuilder
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 theCoordinateReferenceSystems
set for the bounds and theGridFeatureBuilder
are both nonnull but different

