多点的最低成本路径 [英] Least cost path with multiple points

查看:197
本文介绍了多点的最低成本路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将双变量位置点连接在一起以形成一条路线.我的观点指的是鱼的位置,因此我需要仅通过水而不是周围土地的路径.基本上,我需要进行多个最小成本路径分析并将其全部加入.我想在R中进行此操作,因为在那里我比在ArcGIS,python,modelbuilder等方面拥有更多的经验.

I am trying to connect bivariate location points together to form a route. My points refer to fish locations, and so I need paths that only pass through water, and not the surrounding land. Basically, I need to do multiple least cost path analyses and join them altogether. I would like to do this in R, as I have more experience there than I do with ArcGIS, python, modelbuilder, etc.

我已经使用ArcGIS创建了一个成本图,水编码为0,土地编码为"NoData",并将其导入到R中.

I have used ArcGIS to create a cost surface, with water coded as 0 and land coded as "NoData", and have imported this into R.

我尝试使用gdistance pkg中的shortestPath,但是当我尝试仅在两点之间运行R时,R总是对我关闭.例如:

I have tried using shortestPath from the gdistance pkg, but R always shuts down on me when I try running it even just between two points. For example:

costpath=shortestPath(costtrans,c29924[1,],c29924[2,],output="SpatialLines")

我的成本面是"costtrans",而"c29924"是一个包含经纬度的SpatialPointsDataFrame.我计划运行一个循环,以便可以对数据帧中的每一行执行此操作.但是,我不知道为什么R甚至不能很好地处理一次迭代.在最初的论点中将成本面转换为过渡对象时,我确实收到以下警告消息:

where my cost surface is "costtrans", and "c29924" is a SpatialPointsDataFrame with my lat/long locations. I had planned to run a loop so that I could do this for each row in the data frame. However, I do not know why R is not handling even one iteration well. When converting my cost surface to a transition object for the first arguements, I do receive the following warning messages:

Warning messages:
1: In array(ans, c(len.a%/%d2, d.ans), if (!all(vapply(dn.ans, is.null,  :
Reached total allocation of 6057Mb: see help(memory.size)
2: In array(ans, c(len.a%/%d2, d.ans), if (!all(vapply(dn.ans, is.null,  :
Reached total allocation of 6057Mb: see help(memory.size)
3: In as.vector(transition.values) :
Reached total allocation of 6057Mb: see help(memory.size)
4: In as.vector(transition.values) :
Reached total allocation of 6057Mb: see help(memory.size)
5: In .TM.repl.i.mat(as(x, "TsparseMatrix"), i = i, value = value) :
number of items to replace is not a multiple of replacement length

任何解决此问题的建议或其他实现我最初目标的方法将不胜感激!

Any suggestions for solving this, or other approaches to my initial goal would be greatly appreciated!

推荐答案

可以使用gdistance包来做您想做的事情.栅格大小可能是一个问题(即它对于内存而言太大),在这种情况下,您可以使用raster包中的aggregate()对其进行放大.如另一条评论中所述,这也可能与您对陆地和海洋的参数化有关.

It is possible to do what you wish using the gdistance package. It may be an issue with the size of your raster (i.e. it is too big for memory), in which case you can upscale it with aggregate() from the raster package. It may also be an issue with your parameterization of land and sea as noted in another comment.

以下是我想实现的目标的一个示例(如下).我已将土地参数化为高成本障碍(= 10000个成本单位),将海洋参数化为无障碍(= 1个成本单位).还要注意,我采取相反的方法来产生电导表面.如果需要位置之间的路径长度,可以使用costDistance()完成,这将为您提供以地理单位表示的地理路径长度的结果.

Here is an example of what I believe you want to achieve (below). I have parameterized the land as a high cost barrier (=10000 cost units), and the sea as no barrier (=1 cost unit). Note also that I take the inverse to produce a conductance surface. If you want the lengths of the paths between locations, it can be done with costDistance() and this will give you the result as a geographic path length in the units of the raster.

library(gdistance)

## Create cost surface where "land" exists in the middle
cost <- raster(nrow=100, ncol=100, 
           xmn=0, xmx=100, ymn=0, ymx=100, crs="+proj=utm")
cost[] <- 1
cost[cellFromRowColCombine(cost, 50:55,20:80)] <- 10000

## Produce transition matrices, and correct because 8 directions
trCost <- transition(1/cost, mean, directions=8)
trCost <- geoCorrection(trCost, type="c")

## Create three points (representing three points in time series)
pts <- cbind(x=c(20, 60, 40), y=c(80, 60, 20))

## Display results
plot(cost)
plot(SpatialPoints(pts), add=TRUE, pch=20, col="red")
text(pts[,1]+2, pts[,2]+2, 1:nrow(pts))
plot(shortestPath(trCost, pts[1,], pts[2,], output="SpatialLines"), add=TRUE)
plot(shortestPath(trCost, pts[2,], pts[3,], output="SpatialLines"), add=TRUE)

这篇关于多点的最低成本路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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