14.5 Points of interest
poi (Points of Interest)
The osmdata
package provides easy-to-use access to Open Street Map data
Caution: even filtering for metro areas in Germany, this query operates on 2Gb of data.
<- purrr::map(metro_names, function(x) {
shops message("Downloading shops of: ", x, "\n")
Sys.sleep(sample(seq(5, 10, 0.1), 1))
= osmdata::opq(x) |>
query ::add_osm_feature(key = "shop")
osmdata= osmdata::osmdata_sf(query)
points
= 2
iter while (nrow(points$osm_points) == 0 && iter > 0) {
= osmdata_sf(query)
points = iter - 1
iter
}
$osm_points
points
})
# checking if we have downloaded shops for each metropolitan area
= purrr::map_dbl(shops, nrow) == 0
ind if (any(ind)) {
message("There are/is still (a) metropolitan area/s without any features:\n",
paste(metro_names[ind], collapse = ", "), "\nPlease fix it!")
}
# select only specific columns
= purrr::map_dfr(shops, select, osm_id, shop) shops
We will just use the convenient sample dataset with features in each of the metro areas.
data("shops", package = "spDataLarge")
|>
shops ggplot() +
geom_sf(alpha = 0.01, shape = 20) +
theme_minimal()
This spatial point object must be converted into a raster
<- sf::st_transform(shops, st_crs(reclass))
shops
<- terra::rasterize(x = shops, y = reclass, field = "osm_id", fun = "length") poi
As with the other raster layers (population, women, mean age, household size) the poi raster is reclassified into four classes. Here again, some judgement is needed.
The authors choose the Fisher-Jenks natural breaks approach which minimizes within-class variance, the result of which provides an input for the reclassification matrix.
<- classInt::classIntervals(terra::values(poi), n = 4, style = "fisher") int
## Warning in classInt::classIntervals(terra::values(poi), n = 4, style =
## "fisher"): var has missing values, omitted in finding classes
<- round(int$brks)
int
<- matrix(c(int[1], rep(int[-c(1, length(int))], each = 2),
rcl_poi length(int)] + 1), ncol = 2, byrow = TRUE)
int[
<- cbind(rcl_poi, 0:3)
rcl_poi
<- terra::classify(poi, rcl = rcl_poi, right = NA)
poi
names(poi) = "poi"
poi
## class : SpatRaster
## dimensions : 868, 642, 1 (nrow, ncol, nlyr)
## resolution : 1000, 1000 (x, y)
## extent : 4031000, 4673000, 2684000, 3552000 (xmin, xmax, ymin, ymax)
## coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035)
## source(s) : memory
## name : poi
## min value : 0
## max value : 3