Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:43:14+00:00 2026-05-31T11:43:14+00:00

I am trying to connect bivariate location points together to form a route. My

  • 0

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.

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.

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")

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:43:15+00:00Added an answer on May 31, 2026 at 11:43 am

    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.

    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)
    

    Example plot of least-cost paths around land

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to connect to a database that's set to read only, the connection
I'm trying to connect to an application that uses Comet and is pretty heavy
Iam trying to connect my App to a WCF service that I created in
I'm trying to connect to Amazon EC2 using OpenSSH in windows but I need
Iam trying to connect my android device with a bluetooth compatible device. I know
Im trying to connect my project via sFTP. and everytime I run the project
Im trying to connect MySql from VB.NET in visual basic 2010. I wanted to
I trying to connect to a Java Service with some special security requirements It
I am trying to connect to a Servlet with my j2me application and it's
When I am trying to connect to my SVN repository on some remote server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.