Description Usage Arguments Value Examples
View source: R/extractRasterPoly_cl.R
Parallelized function to extract data from a raster or raster stack for indivdiual polygons within a shapefile.
1 2 3 4 5 6 7 8 9 10 11 12 |
shpfile |
The shapefile to be used to intersect with the raster layers |
rast |
The raster layer(s) to be intersected |
catid_col |
the catchment id field in the shpfile |
fun |
The function to apply. Requires a single value is returned (e.g. fun = mean, fun = max). see 'raster::extract“ for more details |
weights |
see 'Raster::extract' |
normalizeWeights |
see 'Raster::extract' |
na.rm |
see 'Raster::extract' |
small |
see 'Raster::extract' |
start |
the first polygon in the shapefile to be used for intersection Defaults to a value of 1 (the first row) |
end |
The last polygon in the shapfile to be intersected. |
a dataframe of area-weighted raster values for each polygon.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #Note the code below will only work on Mac/Unix based systems.
#Other implementations of the parallel processors (e.g. PSOCK) may work on Windows but are untested.
#The following to lines are required to initiate the parallel processors
library(parallel)
no_cores=detectCores()-1
#Define a bounding box for the city of Melbourne, Australia and surrounds
melb <- list(x = c(144.0000, 146.5000), y = c(-39.0000, -37.0000))
awap_stack <- stack_awap(bbox=melb, start='20130131')
vic_cats<-readShapePoly('/Users/nbond/Data/GIS_Data/Australia/BaseData/Catchments/VIC/VIC_CATCHMENTS.shp')
proj4string(vic_cats) <- CRS('+init=epsg:4283')
vic_cats <- spTransform(vic_cats, CRS('+init=epsg:28355'))
vic_cats <- vic_cats[which(vic_cats@data$BNAME %in% c('YARRA RIVER', 'MARIBYRNONG RIVER')),]
plot(awap_stack[[1]])
plot(vic_cats, add=TRUE)
vic_cats_runoff<-extractRasterPoly_cl(vic_cats, rast=melb_awap, catid_col='BNAME')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.