mackaszechno 27 February 2026
see https://rmarkdown.rstudio.com/github_document_format.html for reference here to creating github document (rmarkdown custom template)
Note: what follows is a very crude github md to demonstrate key points.
Current restrictions are based on polygons from kerbside to centreline of road. New procedures require that these be made into polylines that mimick roadmarkings that follow the kerbline.
Issue 1: not all polygons touch kerbline. Buffering either to extract affected kerbline not sufficient.
Issue 2: simply casting polygons to linestrings, insufficient.
Solution: cast polygons to points and, for those vertices not already on the kerbline, compute
Libraries used:
library(sf)
library(dplyr)
library(mapgl)
library(mapview)
library(units)
Data files:
pow <- read_sf("./shapefile/CPE_PROHIBITION_OF_WAITING.shp")
kerb <- read_sf("./shapefile/mm_TopographicLine.shp")
area <- read_sf("./shapefile/mm_TopographicArea.shp")
maplibre_view(kerb) |> add_view(pow, color = "red")
line1 <- pow |> st_cast("LINESTRING") |> mutate(ID = 1:n(), .before = 1)
maplibre_view(kerb1) |> add_view(line1, color = "red")
p1 <- pow |> filter(MI_PRINX == 17407)
pt1 <- p1 |> st_cast("POINT") |> mutate(ID = 1:n(), .before = 1)
maplibre_view(kerb) |> add_view(pt1, color = "red")
Selecting one point clearly not on kerbline and finding st_nearest_points
pt10 <- pt1 |> filter(ID == 10)
bob1 <- st_nearest_points(pt10, kerb) |> st_as_sf()
bob1 <- bob1 |> mutate(dist = st_length(st_geometry(bob1)))
bob1 <- bob1 |> filter(dist < set_units(10, "m"))
bob1 <- bob1 |> arrange(dist) |> slice(1)
bob1 <- bob1 |> arrange(dist) |> slice(1) |> st_cast("POINT")
bob1end <- lwgeom::st_endpoint(bob1) |> st_sfc() |> st_as_sf()
Confirming that endpoint is new location on kerb and not existing vertices on kerb
kerb1osgb1000002048044915 <- kerb1 |> filter(gml_id == "osgb1000002048044915") |> st_cast("POINT")
maplibre_view(bob1, color = "blue", legend = TRUE, layer_id = "bob1") |>
add_view(bob1end, color = "red", layer_id = "bob1end") |>
add_view(pt10, color = "green", layer_id = "pt10") |>
add_view(kerb1, color = "yellow", layer_id = "osmm line") |>
add_view(kerb1osgb1000002048044915, color = "orange", layer = "target feature") |>
add_layers_control()
Wrap the above up into a lowlevel helper function and then create a high level function that checks for vertices on/off kerbline and returns attributes from original polygon and new points. Make new points into new linestring to replace original polygon.
Potentially investigate direction required to allow drawing offset symbology to appear to left of linestring (ie on the road) given location of centreline of road.
Further reading:
https://stackoverflow.com/questions/51292952/snap-a-point-to-the-closest-point-on-a-line-segment-using-sf
https://gis.stackexchange.com/questions/288570/find-nearest-point-along-polyline-using-sf-package-in-r