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,
  OutputFormat = "ROBJECT",
  OutputName = NULL,
  dlon = NA,
  dlat = NA,
  Area = NA,
  cuts = 100,
  cols = c("green", "yellow", "red"),
  NamesIn = NULL
)

Arguments

Input

the name of the Input data as a .csv file or an R dataframe. If a .csv file is used as input, this file must be in your working directory and its name given in quotes e.g. "DataFile.csv".

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

Latitude, Longitude, Variable 1, Variable 2 ... Variable x.

OutputFormat

can be an R object or an ESRI Shapefile. if OutputFormat is specified as "ROBJECT" (the default), a SpatialPolygonDataFrame is created in your R environment. if OutputFormat is specified as "SHAPEFILE", an ESRI Shapefile is exported in your working directory.

OutputName

if OutputFormat is specified as "SHAPEFILE", the name of the output shapefile in quotes (e.g. "MyGrid") must be provided.

dlon

width of the grid cells in decimal degrees of longitude.

dlat

height of the grid cells in decimal degrees of latitude.

Area

area, in square kilometers, of the grid cells.

cuts

Number of desired color classes.

cols

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

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

Value

Spatial object in your environment or ESRI shapefile in your working directory. 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@data).

Finally, colors are generated for each aggregated values according to the chosen cuts (numerical classes) and cols (colors).

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, add_RefGrid, add_col, add_Cscale.

Examples




#Example 1: Simple grid, using automatic colors

MyGrid=create_PolyGrids(Input=GridData,dlon=2,dlat=1)
#View(MyGrid@data)
plot(MyGrid,col=MyGrid$Col_Catch_sum)

#Example 2: Equal area grid, using automatic colors

MyGrid=create_PolyGrids(Input=GridData,Area=10000)
plot(MyGrid,col=MyGrid$Col_Catch_sum)

#Example 3: Equal area grid, using custom cuts and colors

MyGrid=create_PolyGrids(Input=GridData,
       Area=10000,cuts=c(0,50,100,500,2000,3500),cols=c('blue','red'))

plot(MyGrid,col=MyGrid$Col_Catch_sum)

#Example 4: Equal area grid, using custom cuts and colors, and adding a color scale (add_Cscale)

#Step 1: Generate your grid
MyGrid=create_PolyGrids(Input=GridData,Area=10000)

#Step 2: Inspect your gridded data (e.g. sum of Catch) to
#determine whether irregular cuts are required
hist(MyGrid$Catch_sum,100) 
#In this case (heterogeneously distributed data) irregular cuts would be preferable

#Step 3: Generate colors according to the desired classes (cuts)
Gridcol=add_col(MyGrid$Catch_sum,cuts=c(0,50,100,500,2000,3500),cols=c('yellow','purple'))

#Step 4: Plot result and add color scale
Mypar=par(mai=c(0,0,0,2)) #Figure margins as c(bottom, left, top, right)
plot(MyGrid,col=Gridcol$varcol) #Use the colors generated by add_col
#Add color scale using cuts and cols generated by add_col
add_Cscale(title='Sum of Catch (t)',cuts=Gridcol$cuts,cols=Gridcol$cols,width=24) 
par(Mypar)




[Package CCAMLRGIS version 3.0.7 Index]