R/parks_calc_attributes.R
parks_calc_attributes.Rd
Summaries will be calculated for each of the supplied datasets (data_points
, data_lines
, or data_rasters
)
and appended to the parks
data as additional columns.
Ensure that all have a (projected) coordinate reference system similar to parks
.
sf
polygons (with projected coordinate reference system).
Named list of sf
object(s) containing data of geometry type POINT
or MULTIPOINT
.
List names are used to name the park attributes (columns) in the output.
Named list of sf
object(s) containing data of geometry type LINESTRING
or MULTILINESTRING
.
List names are used to name the park attributes (columns) in the output.
Named list of single SpatRaster
object(s) from terra::rast()
.
List names are used to name the park attributes (columns) in the output.
Function to summarise the raster data passed to terra::extract()
.
Defaults to NULL
, which tabulates the sum of each unique value in the raster (i.e. classified raster,
with numbers each representing a specific class/category) using the function raster_class_area()
.
Minimum patch size to be included when tabulating the sum of each raster class.
Only relevant if rasters_summarise_fun = NULL
. Provided either as a units object (see units::set_units()
),
or a number in the units of the coordinate reference system. Defaults to 0
m^2.
numeric. Option to calculate total edge length of (classified) raster(s)
associated with each of the parks
polygons, using the function raster_edge_length()
. The total edge length of raster patches contained within
parks
will be calculated, and patches in close proximity can be included by increasing the value of this argument;
the length of parks
borders that intersect the buffered raster will be calculated.
This provides a way include patches in close proximity to the parks
(e.g. total waterfront length close to parks).
Note that each class (unique value in the raster) will be summarised, including 0
; convert pixels to NA
if you wish to exclude them.
Provided either as a units object (see units::set_units()
),
or a number in the units of the coordinate reference system. Defaults to NULL
(not calculated). Set to 0
to include patches
within parks
only.
logical. Whether or not to calculate relative amounts
(e.g. point density, ratio of line-to-perimeter length, proportional area). Defaults to TRUE
.
character (optional). File path to export output data (GeoJSON format).
Other arguments passed to terra::extract()
.
parks
with added columns containing the summaries of basic park attributes
(area and perimeter), as well as summaries of each of the supplied datasets.
The summary method depends on geometry type (i.e. points, lines or rasters) and supplied arguments.
Some examples:
Area of park polygon.
Perimeter of park polygon.
data_points
>_countTotal count of points within park polygon.
data_points
>_ptdensityTotal count divided by area of the park polygon (point density).
Included if argument relative
set to TRUE
.
data_lines
>_lengthSum of line lengths within park polygon.
data_lines
>_length_perim_ratioRatio of line-to-perimeter length of the park polygon.
Included if argument relative
set to TRUE
.
data_rasters
>Summarised values of a specific raster class
(depends on function provided in the rasters_summarise_fun
argument).
data_rasters
>< class value >_areaTotal area of a specific raster class
(if rasters_summarise_fun = NULL
).
data_rasters
>< class value >_area_pctPercentage area of a specific raster class
(if rasters_summarise_fun = NULL
). Included if argument relative
set to TRUE
.
data_rasters
>< class value >_lengthTotal edge length of a specific raster class.
data_rasters
>< class value >_length_perim_ratioEdge-to-perimeter length of a specific raster class.
Included if argument relative
set to TRUE
.
if (FALSE) {
data(pop_sgp) # city census blocks
data(parks_sgp) # park polygons
# transform to projected crs
pop_sgp <- sf::st_transform(pop_sgp, sf::st_crs(32648))
parks_sgp <- sf::st_transform(parks_sgp, sf::st_crs(32648))
# get playground points (example attribute)
city_boundaries <- pop_sgp %>%
dplyr::filter(year == 2020) %>%
sf::st_union() %>%
sf::st_as_sf() %>%
smoothr::fill_holes(threshold = units::set_units(1, 'km^2')) %>% # clean up
smoothr::drop_crumbs(threshold = units::set_units(1, 'km^2')) %>%
sf::st_make_valid()
playgrounds <- get_playgrounds_osm(place = city_boundaries,
date = as.Date('2021-01-01'))
point_list <- list(playgrounds) # convert to list (can add other point data too)
names(point_list) <- c("playground") # name each element in list
# calculate playground point count & density per park
parks_calc_attributes(parks = parks_sgp,
data_points = point_list,
relative = TRUE)
}