Learn R Programming

dggridR (version 3.1.0)

dgcellstogrid: Return boundary coordinates for specified cells

Description

Returns the coordinates constituting the boundary of a specified set of cells. Duplicates are eliminated to reduce processing and storage requirements.

Usage

dgcellstogrid(dggs, cells, savegrid = NA, return_sf = TRUE)

Value

Returns an sf object. If !is.na(savegrid), returns a filename.

Arguments

dggs

A dggs object from dgconstruct()

cells

The cells to get the boundaries of

savegrid

If savegrid is set to a file path, then a shapefile containing the grid is written to that path and the filename is returned. No other manipulations are done. Default: NA (do not save grid, return it)

return_sf

logical. If FALSE, a long-format data frame giving the coordinates of the vertices of each cell is returned. This is is considerably faster and more memory efficient than creating an sf data frame.

Examples

Run this code
library(dggridR)
data(dgquakes)

#Construct a grid with cells about ~1000 miles wide
dggs          <- dgconstruct(spacing=1000,metric=FALSE)
dgquakes$cell <- dgGEO_to_SEQNUM(dggs,dgquakes$lat,dgquakes$lon)$seqnum

#Get grid cells for the earthquakes identified
grid          <- dgcellstogrid(dggs, dgquakes$cell)

Run the code above in your browser using DataLab