Skip to content
This repository was archived by the owner on Oct 31, 2018. It is now read-only.

vertex/edge neighbours by joins #2

@mdsumner

Description

@mdsumner

Close, need to include the top right.

library(tidyverse)
library(sf)
library(scsf)
demo(nc, ask = FALSE, verbose = FALSE)

par(mfrow = c(3, 1), mar = c(rep(0.75, 4)))

# Target county
plot(nc[1], col = "red", main = "Target county")
plot(nc[50, "AREA"], add = TRUE)

x <- PRIMITIVE(nc)

## filter to the 50th
x50 <- x$object[50, "object_"] %>% inner_join(x$path) %>% 
  inner_join(x$path_link_vertex) %>% 
  inner_join(x$vertex)

## join by vertex 
idx <- x50 %>% dplyr::select(vertex_) %>% 
  inner_join(x$path_link_vertex, "vertex_") %>% 
  inner_join(x$path) %>% 
  distinct(object_) ##%>% inner_join(nc %>% mutate(object_ = x$object_))

plot(nc[, 1], col = "red"); plot(nc[match(idx$object_, x$object$object_), 1], add = TRUE)

## join by at least one edge
idx2 <- x50 %>% dplyr::select(vertex_) %>% 
  inner_join(x$path_link_vertex, "vertex_") %>% 
  group_by(path_, vertex_) %>% mutate(nvert = n()) %>% 
  ungroup() %>% 
  filter(nvert > 1 ) %>% 
  inner_join(x$path) %>% 
  distinct(object_) ##%>% inner_join(nc %>% mutate(object_ = x$object_))

plot(nc[, 1], col = "red"); plot(nc[match(idx2$object_, x$object$object_), 1], add = TRUE)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions