Skip to contents

This function extracts crop rotation information from a raster file and amends the land use data accordingly.

Usage

extract_rotation(df, start_year, tif_name, r_path, lookup, lu_constant = c())

Arguments

df

An sf data.frame with land use. Columns "id" and "type" should be present.

start_year

A numeric value representing the year from which data begins.

tif_name

A string for the name of the .tif raster file.

r_path

A string for the path to the .tif file.

lookup

A dataframe with a "lc1" column for numeric codes and a "type" column for text.

lu_constant

(optional) A vector of strings with land uses to be kept constant in land use (e.g., water, urban areas). Default lu_constant = c().

Value

An sf data.frame with land use amended with crop rotation information.

References

Mészáros, J., & Szabó, B. (2022). Script to derive and apply crop classification based on Sentinel 1 satellite radar images in Google Earth Engine platform. https://doi.org/10.5281/zenodo.6700122

Examples

if (FALSE) {
  library(sf)
  
  # Loading land use/crop layer
  lu_path <- system.file("extdata", "GIS/lu_layer.shp", package = "SWATprepR")
  lu <- st_read(lu_path, quiet = TRUE) %>% mutate(id = row_number())
  
  # Preparing lookup table
  lookup <- data.frame(lc1 = seq(1:length(unique(c(lu$type)))), 
  type = unique(c(lu$type)))
  lu_constant <- c("fesc", "orch", "frst", "frse", "frsd", "urld", "urhd", 
  "wetl", "past", "watr", "agrl")

  # Extracting rotation information from raster
  # Raster information should have been prepared with remote sensing 
  lu_rot <- extract_rotation(lu, 2015, "cropmaps.tif", "./output/", lookup, 
  lu_constant)
}