View source: R/build_aggregation_table.R
calculate_pixel_fractions_single_polygon | R Documentation |
Calculate the fraction of each pixel's area that falls within a single polygon
calculate_pixel_fractions_single_polygon(polygon, id_raster, polygon_id = NULL)
polygon |
terra::SpatVector object of length 1. The polygon to calculate fractional areas across. |
id_raster |
terra::SpatRaster object. ID raster created for the set of all
polygons to be considered, created by |
polygon_id |
(optional). ID for this polygon. Must have length 1. |
This is a helper function called by build_aggregation_table()
.
data.table containing two or three columns:
pixel_id: unique pixel ID from the ID raster
area_fraction: fraction of the pixel area falling within this polygon
polygon_id (optional): If polygon_id
was defined, it is added to the table
build_aggregation_table
## Not run:
polygons <- sf::st_read(system.file('extdata/Benin_communes.gpkg', package = 'mbg'))
id_raster <- build_id_raster(polygons)
pixel_fractions <- calculate_pixel_fractions_single_polygon(
polygon = polygons[1, ], id_raster
)
head(pixel_fractions)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.