Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segment bucket #4

Open
4 tasks
mdsumner opened this issue Dec 5, 2018 · 1 comment
Open
4 tasks

segment bucket #4

mdsumner opened this issue Dec 5, 2018 · 1 comment

Comments

@mdsumner
Copy link
Member

mdsumner commented Dec 5, 2018

Function to crush sets of SC0 objects together and renormalize indexes.

  • convert to useable normalization for SC0.SC0
  • provide RTriangle support in anglr
  • do segment culls for where there won't be any intersections
  • keep track of sources
c.SC0 <- function(...) {
  all_list <- list(...)
  nrs <- integer(length(all_list))
  for (i in seq_along(all_list)) {
    all_list[[i]]$object$id <- i
    nrs[i] <- nrow(all_list[[i]]$vertex)
  }
  ## object here means which element of all_list
  segs <- purrr::map_df(all_list, ~tidyr::unnest(.x$object["topology_"]), .id = "object")
  ## id here means the same (but it didn't exist before)
  #objs <- purrr::map_df(all_list, ~.x$object["id"])
  
  vert <- purrr::map_df(all_list, ~.x$vertex[c("x_", "y_")])
  vdata <- unjoin::unjoin(vert, .data$x_, .data$y_)
  if (nrow(vdata$data) == nrow(vdata$.idx0)) {
    ## we done, just bind the tables after re-indexing
    
  } else {
    uverts <- vdata$.idx0
    segs$.vx0 <- match(vdata$data$.idx0[segs$.vx0], vdata$.idx0$.idx0)
    segs$.vx0 <- match(vdata$data$.idx0[segs$.vx1], vdata$.idx0$.idx0)
  }
  
  topology <- split(segs[c(".vx0", ".vx1")], segs$object)[unique(segs$object)]
  
  incr <- 0
  for (i in seq_along(topology)) {
    topology[[i]]$.vx0 <- topology[[i]]$.vx0 + incr
    topology[[i]]$.vx1 <- topology[[i]]$.vx1 + incr
    incr <- incr + nrs[i]
    print(i)
  }
  out <- structure(list(object = tibble::tibble(topology_ = topology), vertex = vert, 
                        meta = tibble::tibble(proj = NA_character_, ctime = Sys.time())), class = c("SC0", "sc"))
  out
}

library(silicate)
library(raster)
library(sf)
g <- SC0(sf::st_cast(spex::polygonize(raster(matrix(1:12, 3))),  "LINESTRING"))
l <- SC0(SpatialLines(list(Lines(list(Line(list(rbind(c(0.2, 0.2), c(0.5, 0.5), c(0.6, 0.8), c(0.9, 0.9), c(0.2, 0.3))))), "1"))))
plot(g)
plot(l, add = TRUE, col = 1:4)
plot(c(l, g))

l2 <- SC0(SpatialLines(list(Lines(list(Line(list(rbind(c(0.2, 0.2), c(0.5, 0.5), c(0.6, 0.8), c(0.9, 0.9), c(0.2, 0.3), c(0, 0))))), "1"))))
plot(g)
plot(l2, add = TRUE, col = 1:5)
plot(c(l2, g))

library(trip)
data("walrus818", package = "trip")
x <- SC0(walrus818)
g <- SC0(sf::st_cast(spex::polygonize(raster(walrus818))))
c(x, g)
@mdsumner
Copy link
Member Author

mdsumner commented Dec 6, 2018

Well that's totally broken and hopeless. Work on a better approach from this example

  • collate all end point indices and vertices
  • increment end points by merge-logic (+cumul row count)
  • de-duplicate vertices
  • map new end point indices
library(silicate)
library(raster)
library(sf)
g <- SC0(sf::st_cast(spex::polygonize(raster(matrix(1:12, 3))),  "LINESTRING"))

l2 <- SC0(SpatialLines(list(Lines(list(Line(list(rbind(c(0.2, 0.2), c(0.5, 0.5), c(0.6, 0.8), c(0.9, 0.9), c(0.2, 0.3), c(0, 0))))), "1"))))
plot(g)
plot(l2, add = TRUE, col = 1:5)
plot(c(l2, g))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant