首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >栅格中两个最远点之间的距离

栅格中两个最远点之间的距离
EN

Stack Overflow用户
提问于 2021-05-05 06:27:30
回答 1查看 98关注 0票数 0

我有一个地理区域作为栅格文件,我想恢复栅格单元位置之间的最长距离。换句话说,最长的轨迹。(位置由单元格的中心表示)。在R中可以做吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-05 21:00:52

冒着浪费时间的风险,因为没有可重现的例子来检查需要什么以及答案是否正确,这里有一些R代码来做我认为需要做的事情。基本上,查找栅格的边缘,因为最大距离将涉及边缘。从那里,找到所有边缘点对之间的距离,以确定全局最大距离。

代码语言:javascript
复制
library(raster)
library(rgdal)
library(rgeos)

# A reproducible raster file
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
    
# Find the edge of the raster values
b <- boundaries(r)
b[b==0] <- NA
b <- trim(b)
    
# Find the distances between pairs of points 
# using the suggestion from the comments
# so that lon lat data would also work
gd <- pointDistance(rasterToPoints(b)[,1:2], lonlat=FALSE)

# Find the maximum row and column and the points these correspond to
maxpair <- which(gd==max(gd), arr.ind=T)
firstpoint <- df[maxpair[1],]
secondpoint <- df[maxpair[2],]
    
# Plot things
plot(r)
points(firstpoint, col='red', cex=4, pch=10)
points(secondpoint, col='red', cex=4, pch=10)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67392971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档