Description Usage Arguments Details Examples
View source: R/assignZonalRecordsToDatabase.R
The assignZonalRecordsToDatabase
function spatially averages climate records from the
netCDF mosaic files over zones defined by spatial polygons and exports directly to a SQLite database.
1 2 3 | assignZonalRecordsToDatabase(zonesShapefile, zoneField, zoneFieldType = NULL,
mosaicDirectory, variables, years, databaseFilePath = NULL,
databaseTableName = NULL)
|
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. |
zoneFieldType |
Character string defining the column type for the unique ID field written into the database. Options are "character", "integer", "numeric", or the default: NULL. A NULL value will base the type on the shapefile field type as interpreted by R. |
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. |
databaseFilePath |
Character string of the file path to the database to write to. If it does not exist, one will be created. |
databaseTableName |
Character string of the name of the table to create/write to in the database. |
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 SQLite database 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 6 7 8 | assignZonalRecordsToDatabase(zonesShapefile = spatialPolygonsDataFrame,
zoneField = "UNIQUE_ID",
zoneFieldType = "integer",
mosaicDirectory = "C:/USER/Data/Daymet",
variables = c("tmin", "tmax", "prcp"),
years = 1980:1990,
databaseFilePath = "C:/USER/Data/Databases/DaymetDB",
databaseTableName = "climate_record")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.