knitr::opts_chunk$set(echo = TRUE)

Case Study

You have a raster multi-band file containing the values of an index (e.g., EVI) for multiple dates, and a vector file with areas from which you wish to either:

  1. Extract the time serie for each pixel contained in polygon ;
  2. Compute summary statistics on the values of the pixels of each polygon, for each date/band of the raster

Solution

You can use sprawl::extract_rast to quickly extract both the single-pixel time series, and the statistics for each polygon and date

Example

First of all, open the input raster containing the time series, and of the input vector file containing the polygons (i.e., the ROIs) for which you want the values.

# Here I'm using test datasets accessed on the filesystem, but on common usage it would as 
# simple as `in_polys <- read_vect("D:/mypath/myfolder/lc_polys.shp"")

library(raster)
library(sprawl)


in_polys <- read_vect(system.file("extdata","lc_polys.shp", package = "sprawl.data"))
in_rast  <- stack(system.file("extdata", "sprawl_EVItest.tif", package = "sprawl.data"))

Now, in in_polys we have a vector with 13 polygons:

in_polys

, and in in_rast a raster time series with 46 bands:

in_rast

Let's have a look at some bands:

plot_rast(in_rast[[2:7]], limits = c(0,7000), in_poly = in_polys)

To extract the values of pixels included in each polygon, you can then use simply:

extracted_values <- extract_rast(in_rast, in_polys)
extracted_values <- extract_rast(in_rast, in_polys, id_field = "lc_type")

extracted values is a list containing two components:

head(extracted_values$alldata)
head(extracted_values$stats)

These results can be easily used for performing further analysis or plotting (coming soon !)



IREA-CNR-MI/sprawl documentation built on May 27, 2019, 1:12 p.m.