In the addon of the session, we counted the charging stations located within North-Rhine Westphalia (NRW). Still, we did not show how to get a point layer of NRW charging stations (“charger_nrw”).
Subset the data file yourself by relying on the spatial information of the filecharging_points_ger.csv
and a polygon of NRW.
There are two ways to achieve this. How many chargers are located within
NRW?
charging_points_ger.csv
(remember to adjust the crs) in the
./data
folder and polygons of NRW. For the latter, you can
again use the osmdata
syntax.
sf::st_join
and
sf::st_intersection()
. The default of
sf::st_join()
will leave you with a ‘left-join’ and return
a data object with all chargers and matching district information for
those that are located within NRW. You can reset the option to perform
an ‘inner-join’ and keep only the observation that lay within the
predefined area
(sf::st_join(x , y, join = "", left = FALSE)
).
Did the operationalization of train station accessibility convince you? The INKAR database offers another approach: Proportion of residents with max. 1000m linear distance to the nearest public transport stop in the district. We have everything needed to create this indicator on a smaller scale as well. What is the mean share of residents with max 1000m linear distance to the nearest train station in a 5km neighborhood of our fake respondents?
You can run the code below to load all the data you need.
nrw <-
osmdata::getbb(
"Nordrhein-Westfalen",
format_out = "sf_polygon"
) %>%
.$multipolygon %>%
sf::st_transform(3035)
set.seed(1234)
fake_coordinates <-
sf::st_sample(nrw, 1000) %>%
sf::st_sf() %>%
dplyr::mutate(
id_2 =
stringi::stri_rand_strings(10000, 10) %>%
sample(1000, replace = FALSE)
)
nrw_pt_trainstops <- sf::st_read("./data/nrw_pt_osmtrainstops.shp", crs = 3035)
inhabitants_ger <-
z11::z11_get_100m_attribute(Einwohner)
As always, there are several ways to do this. Anne tried to keep the workflow as close to the functions taught in this course as possible and suggests the following steps:
Create a point layer with the centroids of all grids in NRW based on the z11 population layer.
Calculate the distance to the next train station for each grid.
Create a column that equals 0 if the distance to the next train station is >1000m and contains the number of inhabitants if <1000.
Rasterize the sf data object to receive two raster objects: number of inhabitants and number of inhabitants with a max 1000m distance to the next train station.
Calculate the mean for the 5km buffer for each “respondent” for each raster.
Calculate the share.
sf
point layer for the raster object you can use
terra::as.points() %>% sf::st_as_sf()
. To rasterize the
object, you can use
terra::rast(vals = .$colname, resolution = 100)
.