GridsGenerator¶
Generates a regular grid of cells, of their borders or of their corners: on the bounds of a vector, on those of a raster or from a corner with a cell size. The cells are the units of many analyses by area, as the counts of points, the statistics of a raster with RasterCatToFeatureAttribute or the sheets of a map series.
Details¶
The grid has pRows x pCols cells, and its place is taken, in order, from a vector, a raster or the coordinates. With a vector, its bounds are divided in the cells. With a raster, its bounds are divided in the cells as well or, if the cell width and height are given, the cells of that size start from its lower left corner, so the grid can be smaller or larger than the raster. Without maps, the grid starts from the lower left corner pLon, pLat, which are the easting and northing in the crs pCode, not necessarily a longitude and a latitude.
The polygons are the cells. The lines are their borders, pRows + 1 horizontal and pCols + 1 vertical lines, each across the whole grid, the horizontal ones first. The points are the corners of the cells, (pRows + 1) x (pCols + 1). Each feature has an id, starting from 0.
The vertex spacing adds vertices along the sides of the cells and along the lines, so that they keep their shape when they are reprojected, as a grid of a projected crs drawn in lat/long.
Parameters¶
Generates a regular grid of polygons, lines or points, on the bounds of a vector or a raster, or from a corner and a cell size.
Toolbox folder: Vector Processing
Status: Certified
Keywords: Vector, Grid
Authors: Andrea Antonello
Class: org.hortonmachine.modules.GridsGenerator
Inputs
Parameter |
Type |
Unit |
Default |
Description |
|---|---|---|---|---|
|
vector file |
Optional vector map from which to take the bounds, divided in pRows x pCols cells: all the other parameters of the bounds and of the cell size are ignored. |
||
|
raster file |
Optional raster map from which to take the bounds: it is divided in pRows x pCols cells or, if pWidth and pHeight are supplied, the cells of that size start from its lower left corner. The longitude and latitude are ignored. |
||
|
double |
|
The west coordinate of the grid, in the units of its crs (needed if no map is supplied). |
|
|
double |
|
The south coordinate of the grid, in the units of its crs (needed if no map is supplied). |
|
|
Double |
The grid cell width: needed if no map is supplied, optional with a raster map, ignored with a vector map. |
||
|
Double |
The grid cell height: needed if no map is supplied, optional with a raster map, ignored with a vector map. |
||
|
int |
|
The number of rows. |
|
|
int |
|
The number of cols. |
|
|
Double |
The optional distance between the vertices added along the sides of the cells and along the lines. |
||
|
String |
|
The output type: the cells (polygon), their borders (line) or their corners (point). Allowed values: |
|
|
CRS code |
The code of the coordinate reference system of the grid, composed by authority and code number (ex. EPSG:32632). Needed if no map is supplied, the grid takes the crs of the map otherwise. |
Outputs
Parameter |
Type |
Unit |
Description |
|---|---|---|---|
|
output file |
The grid. |
Example¶
The example puts 7 x 7 cells of 500 m on the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data, from its lower left corner:
import org.hortonmachine.modules.GridsGenerator
// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"
var grid = new GridsGenerator()
// the grid starts from the lower left corner of the elevation model
grid.inRaster = folder + "dtm_flanginec.tif"
// 7 x 7 cells of 500 m
grid.pWidth = 500.0
grid.pHeight = 500.0
grid.pCols = 7
grid.pRows = 7
grid.pType = "polygon"
grid.outMap = folder + "grid.shp"
grid.process()
The 49 cells cover 3.5 km on each side, a little less than the elevation model, so its northern and eastern borders stay out of the grid: