extractRasterPoly_cl: Parallelized function to extract data from a raster or raster...

Description Usage Arguments Value Examples

View source: R/extractRasterPoly_cl.R

Description

Parallelized function to extract data from a raster or raster stack for indivdiual polygons within a shapefile.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
extractRasterPoly_cl(
  shpfile,
  rast,
  catid_col,
  fun = mean,
  weights = TRUE,
  normalizeWeights = TRUE,
  na.rm = TRUE,
  small = TRUE,
  start = 1,
  end = nrow(shpfile)
)

Arguments

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.

Value

a dataframe of area-weighted raster values for each polygon.

Examples

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

nickbond/catchstats documentation built on Nov. 22, 2019, 3:41 a.m.