create_PolyGrids {CCAMLRGIS} | R Documentation |
Create a Polygon Grid
Description
Create a polygon grid to spatially aggregate data in cells of chosen size. Cell size may be specified in degrees or as a desired area in square kilometers (in which case cells are of equal area).
Usage
create_PolyGrids(
Input,
NamesIn = NULL,
dlon = NA,
dlat = NA,
Area = NA,
cuts = 100,
cols = c("green", "yellow", "red")
)
Arguments
Input |
input dataframe. If Latitude, Longitude, Variable 1, Variable 2 ... Variable x. |
NamesIn |
character vector of length 2 specifying the column names of Latitude and Longitude fields in
the
|
dlon |
numeric, width of the grid cells in decimal degrees of longitude. |
dlat |
numeric, height of the grid cells in decimal degrees of latitude. |
Area |
numeric, area in square kilometers of the grid cells. The smaller the |
cuts |
numeric, number of desired color classes. |
cols |
character, desired colors. If more that one color is provided, a linear color gradient is generated. |
Value
Spatial object in your environment.
Data within the resulting spatial object contains the data provided in the Input
after aggregation
within cells. For each Variable, the minimum, maximum, mean, sum, count, standard deviation, and,
median of values in each cell is returned. In addition, for each cell, its area (AreaKm2), projected
centroid (Centrex, Centrey) and unprojected centroid (Centrelon, Centrelat) is given.
To see the data contained in your spatial object, type: View(MyGrid)
.
Also, colors are generated for each aggregated values according to the chosen cuts
and cols
.
To generate a custom color scale after the grid creation, refer to add_col
and
add_Cscale
. See Example 4 below.
See Also
create_Points
, create_Lines
, create_Polys
,
create_Stations
, create_Pies
, add_col
,
add_Cscale
, add_Legend
.
Examples
# For more examples, see:
# https://github.com/ccamlr/CCAMLRGIS#create-grids
# And:
# https://github.com/ccamlr/CCAMLRGIS/blob/master/Advanced_Grids/Advanced_Grids.md
#Simple grid, using automatic colors
MyGrid=create_PolyGrids(Input=GridData,dlon=2,dlat=1)
#View(MyGrid)
plot(st_geometry(MyGrid),col=MyGrid$Col_Catch_sum)