create_PolyGrids: Create a Polygon Grid

View source: R/create.R

create_PolyGridsR 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). Using Blank=TRUE (with caution) produces an empty grid.

Usage

create_PolyGrids(
  Input,
  NamesIn = NULL,
  dlon = NA,
  dlat = NA,
  Area = NA,
  cuts = 100,
  cols = c("green", "yellow", "red"),
  Blank = FALSE
)

Arguments

Input

input dataframe.

If NamesIn is not provided, the columns in the Input must be in the following order:

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 Input. Latitudes name must be given first, e.g.:

NamesIn=c('MyLatitudes','MyLongitudes').

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 Area, the longer it will take.

cuts

numeric, number of desired color classes.

cols

character, desired colors. If more that one color is provided, a linear color gradient is generated.

Blank

logical, TRUE or FALSE. If TRUE, creates an empty grid spanning the bounding box given in the Input as: c(LatMin,LatMax,LonMin,LonMax). The script might struggle to reach equal-area gridding if the desired cell Area is too large, and/or the Input bounding box is too small, and/or the Input bounding box does not span -180 to 180 degrees longitude. Use Blank=TRUE with caution.

Value

Spatial object in your environment.

if Blank=FALSE:

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. 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.

if Blank=TRUE:

An empty grid is generated. It can be re-used across scripts in conjunction with assign_areas.

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)





CCAMLRGIS documentation built on March 3, 2026, 9:08 a.m.