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.

parks_calc_attributes(
  parks,
  data_points = list(),
  data_lines = list(),
  data_rasters = list(),
  rasters_summarise_fun = NULL,
  raster_min_patch_size = units::set_units(0, "m^2"),
  raster_edge = NULL,
  relative = TRUE,
  filename = NULL,
  ...
)

Arguments

parks

sf polygons (with projected coordinate reference system).

data_points

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.

data_lines

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.

data_rasters

Named list of single SpatRaster object(s) from terra::rast(). List names are used to name the park attributes (columns) in the output.

rasters_summarise_fun

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().

raster_min_patch_size

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.

raster_edge

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.

relative

logical. Whether or not to calculate relative amounts (e.g. point density, ratio of line-to-perimeter length, proportional area). Defaults to TRUE.

filename

character (optional). File path to export output data (GeoJSON format).

...

Other arguments passed to terra::extract().

Value

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

Area of park polygon.

perimeter

Perimeter of park polygon.

< object name in data_points >_count

Total count of points within park polygon.

< object name in data_points >_ptdensity

Total count divided by area of the park polygon (point density). Included if argument relative set to TRUE.

< object name in data_lines >_length

Sum of line lengths within park polygon.

< object name in data_lines >_length_perim_ratio

Ratio of line-to-perimeter length of the park polygon. Included if argument relative set to TRUE.

< object name in data_rasters >

Summarised values of a specific raster class (depends on function provided in the rasters_summarise_fun argument).

< object name in data_rasters >< class value >_area

Total area of a specific raster class (if rasters_summarise_fun = NULL).

< object name in data_rasters >< class value >_area_pct

Percentage area of a specific raster class (if rasters_summarise_fun = NULL). Included if argument relative set to TRUE.

< object name in data_rasters >< class value >_length

Total edge length of a specific raster class.

< object name in data_rasters >< class value >_length_perim_ratio

Edge-to-perimeter length of a specific raster class. Included if argument relative set to TRUE.

Examples

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)
}