r - least cost path with multiple points -


i trying connect bivariate location points form route. points refer fish locations, , need paths pass through water, , not surrounding land. basically, need multiple least cost path analyses , join them altogether. in r, have more experience there arcgis, python, modelbuilder, etc.

i have used arcgis create cost surface, water coded 0 , land coded "nodata", , have imported r.

i have tried using shortestpath gdistance pkg, r shuts down on me when try running between 2 points. example:

costpath=shortestpath(costtrans,c29924[1,],c29924[2,],output="spatiallines") 

where cost surface "costtrans", , "c29924" spatialpointsdataframe lat/long locations. had planned run loop each row in data frame. however, not know why r not handling 1 iteration well. when converting cost surface transition object first arguements, receive 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, value = value) : number of items replace not multiple of replacement length 

any suggestions solving this, or other approaches initial goal appreciated!

-m

it possible wish using gdistance package. may issue size of raster (i.e. big memory), in case can upscale aggregate() raster package. may issue parameterization of land , sea noted in comment.

here example of believe want achieve (below). have parameterized land high cost barrier (=10000 cost units), , sea no barrier (=1 cost unit). note take inverse produce conductance surface. if want lengths of paths between locations, can done costdistance() , give result geographic path length in units of raster.

library(gdistance)  ## create cost surface "land" exists in 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, , correct because 8 directions trcost <- transition(1/cost, mean, directions=8) trcost <- geocorrection(trcost, type="c")  ## create 3 points (representing 3 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) 

example plot of least-cost paths around land


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -