hypertidy/anglr

something puts object_ on triangle table

Closed this issue · 1 comments

Same as

#77

dp <- "/rdsi/PUBLIC/raad/data/listdata.thelist.tas.gov.au/opendata/data"
dsn1 <- file.path(dp, "list_parcels_hobart.gdb")
dsn2 <- file.path(dp, "list_5m_contours_hobart.gdb")
layer1 <- "list_parcels_hobart"
layer2 <- "list_5m_contours_hobart"
library(sf)
cad0 <- read_sf(dsn1, layer1)
cont0 <- read_sf(dsn2, layer2 )

library(raster)
e <- new("Extent"
         , xmin = 523391.060663871
         , xmax = 524529.793420587
         , ymin = 5249817.21778203
         , ymax = 5250452.78955322
)

bb <- st_bbox(e)
cad <- st_crop(cad0, bb)
cont <- st_cast(st_crop(cont0,bb), "MULTILINESTRING")

library(silicate)
library(anglr)
cad_sc <- SC(cad)
cont_sc <- copy_down(SC(cont), "ELEVATION")

## merge edge sets
library(dplyr)
x <- cad_sc
x$object <- bind_rows(x$object["object_"], cont_sc$object["object_"])
x$object_link_edge <- bind_rows(x$object_link_edge, cont_sc$object_link_edge)
x$edge <- bind_rows(x$edge, cont_sc$edge)
x$vertex <- bind_rows(x$vertex, cont_sc$vertex)
## remap vertices
uj <- unjoin::unjoin(x$vertex, x_, y_, key_col = "old")

newv <- uj$old %>% mutate(vertex_ = sc_uid(uj$old))
mapp <- inner_join(uj$old, uj$data) %>% arrange(old)

x$edge$.vx0 <- newv$vertex_[match(mapp$old[match(x$edge$.vx0, mapp$vertex_)], uj$old$old)]
x$edge$.vx1 <- newv$vertex_[match(mapp$old[match(x$edge$.vx1, mapp$vertex_)], uj$old$old)]
newv$old <- NULL
x$vertex <- newv
plot(x) ## check

# str(setdiff(x$object$object_, x$object_link_edge$object_))
# str(setdiff(x$object_link_edge$edge_, x$edge$edge_))
# str(setdiff(c(x$edge$.vx0, x$edge$.vx1), x$vertex$vertex_))

y <- DEL(x)
# Warning messages:
#   1: In max(TRIS[[i]]) : no non-missing arguments to max; returning -Inf
# 2: In max(TRIS[[i]]) : no non-missing arguments to max; returning -Inf
# 3: In max(TRIS[[i]]) : no non-missing arguments to max; returning -Inf
# 4: In max(TRIS[[i]]) : no non-missing arguments to max; returning -Inf


plot(y)
#Error in left_join_impl(x, y, by_x, by_y, aux_x, aux_y, na_matches) : 
#  Can't join on 'vertex_' x 'vertex_' because of incompatible types (character / logical)
  

Also, warnings on max(TRIS).

Pretty sure the plot error is from object_ on triangle.

(That heinous re-indexing is the final stages of #16 )

Fixed, a beautiful thing

image