Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中使用deldir进行Delaunay三角剖分后,如何提取点之间的距离?_R_Distance_Spatial_Delaunay_Deldir - Fatal编程技术网

在R中使用deldir进行Delaunay三角剖分后,如何提取点之间的距离?

在R中使用deldir进行Delaunay三角剖分后,如何提取点之间的距离?,r,distance,spatial,delaunay,deldir,R,Distance,Spatial,Delaunay,Deldir,我想使用Delaunay三角剖分计算城市之间的距离。我有20个城市的经度和纬度,我想计算它们之间的距离,但我在计算如何从三角测量中提取距离信息时遇到了一些困难。到目前为止,我已经使用了deldir()(来自库deldir)。请参阅下面的代码 x <- c(2.3,3.0,7.0,1.0,3.0,8.0) y <- c(2.3,3.0,2.0,5.0,8.0,9.0) try <- deldir(x,y,list(ndx=2,ndy=2),c(0,10,0,10)) s

我想使用Delaunay三角剖分计算城市之间的距离。我有20个城市的经度和纬度,我想计算它们之间的距离,但我在计算如何从三角测量中提取距离信息时遇到了一些困难。到目前为止,我已经使用了deldir()(来自库deldir)。请参阅下面的代码

x   <- c(2.3,3.0,7.0,1.0,3.0,8.0)
y   <- c(2.3,3.0,2.0,5.0,8.0,9.0)
try <- deldir(x,y,list(ndx=2,ndy=2),c(0,10,0,10))

str(try)
List of 8
$ delsgs  :'data.frame':    23 obs. of  6 variables:
..$ x1  : num [1:23] 3 7 7 1 1 3 3 3 8 8 ...
..$ y1  : num [1:23] 3 2 2 5 5 8 8 8 9 9 ...
..$ x2  : num [1:23] 2.3 2.3 3 2.3 3 3 7 1 7 3 ...
..$ y2  : num [1:23] 2.3 2.3 3 2.3 3 3 2 5 2 8 ...
..$ ind1: num [1:23] 2 3 3 4 4 5 5 5 6 6 ...
..$ ind2: num [1:23] 1 1 2 1 2 2 3 4 3 5 ...
$ dirsgs  :'data.frame':    15 obs. of  8 variables:
..$ x1  : num [1:15] 1.65 4.56 5.75 0 1.65 ...
..$ y1  : num [1:15] 3.65 0.74 5.5 2.86 3.65 ...
..$ x2  : num [1:15] 4.56 4.51 4.56 1.65 3.5 ...
..$ y2  : num [1:15] 0.74 0 0.74 3.65 5.5 ...
..$ ind1: num [1:15] 2 3 3 4 4 5 5 5 6 6 ...
..$ ind2: num [1:15] 1 1 2 1 2 2 3 4 3 5 ...
..$ bp1 : logi [1:15] FALSE FALSE FALSE TRUE FALSE FALSE ...
..$ bp2 : logi [1:15] FALSE TRUE FALSE FALSE FALSE FALSE ...
$ summary :'data.frame':    10 obs. of  9 variables:
..$ x       : num [1:10] 2.3 3 7 1 3 8 0 10 0 10
..$ y       : num [1:10] 2.3 3 2 5 8 9 0 0 10 10
..$ n.tri   : num [1:10] 4 4 6 5 5 5 4 3 4 2
..$ del.area: num [1:10] 4.5 6.05 18.67 7.5 15 ...
..$ del.wts : num [1:10] 0.045 0.0605 0.1867 0.075 0.15 ...
..$ n.tside : num [1:10] 4 4 5 4 5 3 1 1 2 1
..$ nbpt    : num [1:10] 4 0 4 2 2 4 2 2 2 2
..$ dir.area: num [1:10] 9.09 10.74 23.32 9.39 18.06 ...
..$ dir.wts : num [1:10] 0.0909 0.1074 0.2332 0.0939 0.1806 ...
$ n.data  : int 6
$ n.dum   : int 4
$ del.area: num 100
$ dir.area: num 100
$ rw      : num [1:4] 0 10 0 10
- attr(*, "class")= chr "deldir"

x解决方案:

计算所有可能的距离,并将其存储到名为
all.distance
(距离以米为单位)的矩阵中。(dat是包含纬度和经度的源数据帧)

读取为列,因此位置“1”与位置“6”、“7”、“8”相邻。位置“2”与位置“4”、“7”、“5”、“8”等相邻

现在是聪明的部分。。。 您需要使用邻域的组合作为距离矩阵中所需值的坐标。并将这些值提取到向量中

为距离值创建空向量:

nb.dist<-numeric(sum(sapply(tree.nb, length)))

享受:)

请遵循此处的指导原则:。坦率地说,我们是一个非常受欢迎的群体,但我不会在这方面提供帮助,因为你甚至没有表现出愿意通过遵守社区最基本的惯例而成为社区的一部分,同时在你可能自己回答的问题上得到大量帮助。请考虑了解更多关于StackOverflow和如何使用该网站,并成为一个良好的社区成员。试着从这里开始@Annemarie,为了保持SO社区的良好一面,做以下三件事。(a) 通过包含一些代码来表明您试图自己解决问题(b)确保代码最小且可复制,以便可以将其复制到其他人的R设置中进行实验(c)通过单击最佳答案左上角的白色大勾号接受每个问题的最佳答案。在过去的7个问题中,你只接受了2个问题的答案,这意味着你没有认识到回答者的努力。人们会生气,不再帮助你。
library(tripack)
tree.nb<-neighbours(tri.mesh(dat$lat,dat$lon))
my.FC<-rep(c(1:length(tree.nb)), sapply(tree.nb, length))
my.SC<-unlist(tree.nb)
my.FC
[1]
1  1  1  2  2  2  2  3  4  4

my.SC
[1]
6  7  8  4  7  5  8  5  2  9
nb.dist<-numeric(sum(sapply(tree.nb, length)))
for (i in 1:sum(sapply(tree.nb, length)))
    nb.dist[i] <- all.distances[my.FC[i],my.SC[i]]
unique(nb.dist)