Skip to content

begin of use with geos strtree #145

@mdsumner

Description

@mdsumner
coords <- function(x) {
  cd <- wk::wk_coords(x)[,c("x", "y")]
  wk::xy(cd[,1L], cd[,2L], crs = wk::wk_crs(x))
}

read_geom <- function(x) {
  rga <- x$returnGeomAs
  x$returnGeomAs <- "WKB"
  out <- x$getNextFeature()
  if (is.null(out)) return(NULL)
  x$returnGeomAs <- rga
  dplyr::bind_cols(tibble::as_tibble(head(out, -1)), tibble::tibble(geometry = wk::wkb(out$geometry, crs = x$getSpatialRef())))
}

dsn <- sds::CGAZ()
v <- new(GDALVector, dsn)
#v$returnGeomAs <- "WKB"
v$resetReading()
read_geom(v)

## first time 
pts <- coords(g)
idx <- geos_strtree_query(geos_strtree(pts), pts)
idx2 <- idx[lengths(idx) > 1]
table <- tibble::tibble(id = seq_along(pts), id2 = id)
for (i in seq_along(idx2)) {
  table$id2[idx2[[i]][2]] <- idx2[[i]][1]
}
pts <- pts[sort(unique(table$id2))]

a <- 0
## now repeat 
while(!is.null(g)) {
  g <- read_geom(v)
  
  pts <- c(pts, coords(g))
  idx <- geos_strtree_query(geos_strtree(pts), pts)
  idx2 <- idx[lengths(idx) > 1]
  table <- dplyr::bind_rows(tibble::tibble(id = seq_along(pts) + nrow(table), id2 = id))
  for (i in seq_along(idx2)) {
    table$id2[idx2[[i]][2]] <- idx2[[i]][1]
  }
  pts <- pts[sort(unique(table$id2))]
  print(g)  
}




Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions