Description Usage Arguments Details Examples
View source: R/assignZonalRecordsToDataframe.R
The assignZonalRecordsToDataframe
function patially averages climate records from the
netCDF mosaic files over zones defined by spatial polygons and returns a dataframe.
1 2 | assignZonalRecordsToDataframe(zonesShapefile, zoneField, mosaicDirectory,
variables, years)
|
zonesShapefile |
A SpatialPolygonsDataFrame of the zones which will be assigned climate records. The object should have a unique ID column and be in the WGS geographic coordinate system (same as the Daymet NetCDF files, proj4string = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"). |
zoneField |
Character string of the field name describing the unique ID values that define the zones. |
mosaicDirectory |
Character string of the file path to the folder containing the netCDF mosaic files. |
variables |
Vector of character strings indicating the variables to process. |
years |
Vector of numeric values indicating the years to process. |
The netCDF files are read and spatially indexed using custom internal functions. The climate time series are assigned to the zones represented by the "zonesShapefile" object. If only one record falls into a polygon it is assigned directly. If multuple records fall into a single polygon, they are averaged. If no records fall into a polygon, the record nearest to the polygon centroid is assigned. The ouput is written to a dataframe in long format with columns for the "zoneField", date, and each of the climate variables.
The function relies on the default naming scheme for the netCDF mosaics (e.g. "prcp_2008.nc4").
If the original shapefile is large enough to cause memory problems, the function can be iterated over the
results of the tileShapefile
function which splits the spatial polygon into manageable chunks.
1 2 3 4 5 | assignZonalRecordsToDataframe(zonesShapefile = spatialPolygonsDataFrame,
zoneField = "UNIQUE_ID",
mosaicDirectory = "C:/USER/Data/Daymet",
variables = c("tmin", "tmax", "prcp"),
years = 1980:1990)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.