nptscot/rnetmatch

R* Tree visualization

Closed this issue · 1 comments

Objective is to create an informative visualization of the R-trees and the candidate matching process. Should find a network portion that is best for this.

All overlapping bounding boxes are compared

library(sf)
library(rsgeo)

rnet_y = stplanr::route_network_small

# The target object
rnet_x = stplanr::rnet_subset(stplanr::osm_net_example[1], rnet_y)


x <- as_rsgeo(sf::st_transform(rnet_x, 27700))
y <- as_rsgeo(st_transform(rnet_y, 27700))

# axis-aligned-bounding-box for x
xbb <- bounding_rect(x)

# creating bounding rects for y
# need to expand them
ybb <- bounding_rect(explode_lines(y))

# define function to expand the AABB
expand_aabb <- function(x, DT) {
  crds <- coords(x)
  # xmin, max, max, min, min
  # ymin min max max min
  crds[,1] <- crds[,1] + (c(-1, 1, 1, -1, -1)  * DT)
  crds[,2] <- crds[,2] + (c(-1, -1, 1, 1, -1)  * DT)
  rsgeo::geom_polygon(crds$x, crds$y, crds$polygon_id)
}

library(ggplot2)

ggplot() +
  geom_sf(
    data = st_as_sfc(xbb), 
    fill = "#76b5c5", alpha = 0.25, lwd = 0
  ) + 
  geom_sf(
    data = st_as_sfc(expand_aabb(ybb, 5)),
    fill = "#e28743", alpha = 0.25,lwd = 0
  ) +
  theme_void()

Nice Viz!