Download and process OpenStreetMap (OSM) park polygons within a specified geographical place
,
from the Geofabrik database. It is a wrapper around
functions in the package osmextract
, and
processes the downloaded files for subsequent analyses. Refer to package osmextract
for
more details and options for input arguments when downloading the data.
get_parks_osm(
place,
date = NULL,
mutually_exclusive_with = list(),
snap_tolerance = 5,
min_area = units::set_units(0, "m^2"),
aggregate_polygons = 15,
dir_raw = osmextract::oe_download_directory(),
filename = NULL,
...
)
sf
object (with projected coordinate reference system). Geographical area to match with the (.osm.pbf
) file in the data archive.
Argument passed to osmextract::oe_match()
.
Date of OSM data snapshot to download. Object of class "Date" in format %Y-%m-%d
. Refer to https://download.geofabrik.de
for the specific dates available. Defaults to NULL
(download the latest available data).
list of sf
object(s). This may be used to
ensure that polygons (e.g. parks, beaches, informal nature areas) are mutually-exclusive (i.e. non-overlapping).
Remove output polygons contained within, as well as intersections between,
each element of this list. Should have the same coordinate reference system as place
.
numeric. Argument for tolerance
level passed to sf::st_snap()
,
used to rectify nearly coincident edges between polygons before processing (e.g. sf::st_contains()
, sf::st_covers()
).
Provided either as a units object (see units::set_units()
), or a number in the units of the coordinate reference system.
Defaults to 5
. Set to 0
if you do not wish to rectify minor overlaps.
numeric. Specify minimum area of each polygon to be retained in the output,
passed to argument threshold
in smoothr::drop_crumbs()
.
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. Argument for dist
passed to sf::st_buffer()
.
Buffered polygons that overlap will be aggregated into multipolygons.
Set to NULL
if you do not wish to aggregate to multipolygons.
character. Directory to download the raw unprocessed OSM data. Passed to
argument download_directory
in osmextract::oe_read()
.
character (optional). File path to export output data (GeoJSON format).
Other arguments passed to osmextract::oe_read()
.
The processed park polygons (sf
object).
OSM polygons are filtered by key-value attributes, where leisure:
is park
, garden
or nature_reserve
,
and access:
is not no
or private
, as well as the key-value pair tourism:zoo
.
If mutually_exclusive_with
is provided, intersections between
the output and these polygon(s) will be excluded using polygons_mutually_exclude()
.
Polygons are then cleaned up using polygons_clean()
.
if (FALSE) {
data(pop_sgp)
pop_sgp <- sf::st_transform(pop_sgp, sf::st_crs(32648)) # transform to projected crs
# merge all census blocks for chosen year (2020) into single multi-polygon
# function requires that polygons are merged
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()
# run function
get_parks_osm(place = city_boundaries,
date = as.Date('2021-01-01'),
snap_tolerance = 5,
aggregate_polygons = 15,
filename = 'public-parks_osm-polygons_2021-01-01.geojson')
}