Voronoi镶嵌的共享边表 [英] Table of shared edges for a Voronoi tesslleation

查看:10
本文介绍了Voronoi镶嵌的共享边表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于spatstat库的dirichlet()函数生成的Voronoi镶嵌(也称为Dirichlet镶嵌或Thiessen多边形)创建一个多边形邻接表。例如,在下图中,右上角和右下角的瓷砖各有2个邻居,右中瓷砖有4个邻居,其余两个瓷砖各有3个邻居。我想捕获表中的邻居对,理想情况下捕获它们共享的边界线的长度:例如,‘Tile1’、‘Tile2’、‘Shared_Edge_Length’。

最初,我尝试使用intersect.tess()intersect.own()以及polyclip函数遍历和比较镶嵌中的每一对多边形,但我猜这些都不起作用,因为根据定义,这些平铺在面积上并不重叠,尽管它们有相同的边。有没有一个简单的函数来实现这一点(另一种方法可能是遍历$bdry点)?regeos包似乎有gTouches,但我找不到与spatstat类似的包。

这是我当前的非工作方法:

library(spatstat)
points <- ppp(x=c(-77.308703, -77.256582, -77.290600,  -77.135668, -77.097144),
         y=c(39.288603, 39.147019, 39.372818, 39.401898, 39.689203),
         window=owin(xrange=c(-77.7,-77), yrange=c(39.1, 39.7)))
vt <- dirichlet(points) # Dirichlet tesselation
plot(vt)

tilesA <- tiles(vt)
n_tiles <- length(tilesA)
boundary_calcs <- data.frame('area1_id'=numeric(), 'area2_id'=numeric(), 'neighbor'=logical()) # Store boundary pairs
for (i in 1:n_tiles) {
  for (j in 1:n_tiles) {
    intersection <- intersect.owin(tilesA[[i]], tilesA[[j]], fatal=FALSE) # does not work
    if (!is.empty(intersection)) {
      boundary_calcs[nrow(boundary_calcs)+1, ] <- c(i, j, TRUE) # add to data table as new row
} } }

推荐答案

以下函数由包作者提供。它使用deldir()函数的dirsgs结构输出镶嵌中每条线的开始/结束坐标以及点索引。这些可以转换为psp线段模式,它可以使用lengths.psp()轻松地提供每个线段的长度。下面的代码生成了一个表格,其中7条边各占一行,如上图所示。

library(spatstat)
library(deldir)
points <- ppp(x=c(-77.308703, -77.256582, -77.290600,  -77.135668, -77.097144),
         y=c(39.288603, 39.147019, 39.372818, 39.401898, 39.689203),
         window=owin(xrange=c(-77.7,-77), yrange=c(39.1, 39.7)))

sharededge <- function(X) {
   verifyclass(X, "ppp")
   Y <- X[as.rectangle(X)]
   dX <- deldir(Y)
   DS <- dX$dirsgs
   xyxy <- DS[,1:4]
   names(xyxy) <- c("x0","y0","x1","y1")
   sX <- as.psp(xyxy,window=dX$rw)
   marks(sX) <- 1:nobjects(sX)
   sX <- sX[as.owin(X)]
   tX <- tapply(lengths.psp(sX), marks(sX), sum)
   jj <- as.integer(names(tX))
   ans <- data.frame(ind1=DS[jj,5], 
                     ind2=DS[jj,6], 
                     leng=as.numeric(tX))
   return(ans)
}

shared_edge_lengths <- sharededge(points)

shared_edge_lengths中存储的输出:

  ind1 ind2       leng
1    2    1 0.17387212
2    3    1 0.13444458
3    4    1 0.05791519
4    4    2 0.10039321
5    4    3 0.25842530
6    5    3 0.09818828
7    5    4 0.17162429

这篇关于Voronoi镶嵌的共享边表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆