1

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 file charging_points_ger.csv and a polygon of NRW. There are two ways to achieve this. How many chargers are located within NRW?
You need two datasets for that: the point layer 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.
There are two functions you can explore: 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)).

2

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:

  1. Create a point layer with the centroids of all grids in NRW based on the z11 population layer.

  2. Calculate the distance to the next train station for each grid.

  3. Create a column that equals 0 if the distance to the next train station is >1000m and contains the number of inhabitants if <1000.

  4. 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.

  5. Calculate the mean for the 5km buffer for each “respondent” for each raster.

  6. Calculate the share.

In the add-on slides of the raster session, Stefan introduced and gave some information on how to transform the raster to points (and back). To get a 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).