
Area of forest change
AreaCalc.Rd
Calculates the changes in forest area based on a rasterObject
forest
mask and a SpatialPolygonsDataFrame
containing areas of interest.
Usage
AreaCalc(
inputForestMap = NULL,
studysite = NULL,
latlon = NULL,
polyName = NULL,
ncores = 1,
saveCSV = FALSE,
years = 2001:2018
)
Arguments
- inputForestMap
A
RasterLayer
object with forest cover represented in binary (e.g 0 represents no forest; 1 represents forest). Each layer is expected to represent one year in theyears
object in a consecutive order.- studysite
An object of type
sf
with a given number of polygons defining the areas of interest. Forest area statistics will be calculated for features in thestudysite
object.- latlon
logical
: Indicates whether or not theinputForestMap
object is based on a geographic coordinate system or is projected to a planar coordinate system. In the former case, area is approximated byraster::area
.- polyName
charachter
of length 1. Indicates the column in the data frame of thestudysite
object to uniquely identify the features of interest. The function will fail if there is no unique identification of the polygons- ncores
The number of cores to use, i.e. at most how many child processes will be run simultaneously.
- saveCSV
Default is
FALSE
. You can specify a directory on your local machine where the results area saved in.csv
format. The features will be identified by the column specified inpolyName
.- years
A vector of type
numeric
indicating the years which are represented by pixels. For GFW data and the default these are 2001 to 2018.
Value
The studysite
object with its data frame appended columnwise
for every single entry in the years
object representing the total area
of forest in a given layer of the inputForestMap
object.
If latlon=TRUE
the returned area is in km², otherwise in the
squared unit of the input projection (most commonly in meters).
Note
This function relies heavily on parallization, indicating the importance of both, a high number of CPUs and large enough RAM.
Author
Darius Görgen (MapTailor Geospatial Consulting GbR) info@maptailor.net
Maintainer: MAPME-Initiative contact@mapme-initiative.org
Contact Person: Dr. Johannes Schielein
Copyright: MAPME-Initiative
License: GPL-3
Examples
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
library(raster)
#> Loading required package: sp
library(mapme.forest)
aoi = st_read(system.file("extdata", "aoi_polys.gpkg", package = "mapme.forest"))
#> Reading layer `aoi_polys' from data source
#> `/home/runner/work/_temp/Library/mapme.forest/extdata/aoi_polys.gpkg'
#> using driver `GPKG'
#> Simple feature collection with 8 features and 1 field
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: 107.1291 ymin: 16.59741 xmax: 107.2502 ymax: 16.6916
#> Geodetic CRS: WGS 84
yearlyRaster = stack(system.file("extdata", "pkgTest_yearlyCover.tif",
package = "mapme.forest"))
result = AreaCalc(inputForestMap = yearlyRaster,
studysite = aoi[1,],
latlon = TRUE,
polyName = "id",
ncores = 1,
saveCSV = FALSE,
years = 2000:2018)
str(result)
#> Classes ‘sf’ and 'data.frame': 1 obs. of 21 variables:
#> $ id : int 1
#> $ area_2000: num 0.722
#> $ area_2001: num 0.722
#> $ area_2002: num 0.722
#> $ area_2003: num 0.722
#> $ area_2004: num 0.721
#> $ area_2005: num 0.491
#> $ area_2006: num 0.135
#> $ area_2007: num 0.135
#> $ area_2008: num 0.129
#> $ area_2009: num 0.128
#> $ area_2010: num 0.128
#> $ area_2011: num 0.128
#> $ area_2012: num 0.0685
#> $ area_2013: num 0.0371
#> $ area_2014: num 0.0275
#> $ area_2015: num 0.0264
#> $ area_2016: num 0.0257
#> $ area_2017: num 0.0257
#> $ area_2018: num 0.0257
#> $ geom :sfc_POLYGON of length 1; first list element: List of 1
#> ..$ : num [1:5, 1:2] 107 107 107 107 107 ...
#> ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
#> - attr(*, "sf_column")= chr "geom"
#> - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
#> ..- attr(*, "names")= chr [1:20] "id" "area_2000" "area_2001" "area_2002" ...