1

I am a beginner in GRASS but I would like to get the least-cost path between two polygons. More exactely, I would like to get the smallest cost from any point situated at the edge of one polygon (polygon A) to any point situated at the edge of another polygon (polygon B).

Until now, I used the function CostDistance and CostPath of ArcGIS by using a cost raster where each cell had a cost value, a shapefile for the first polygon, and a shapefile for the second polygon. I would like to do the same thing with GRASS. I think that the function r.cost allows to do this. But I don't know how to specify in parameters the two polygons in GRASS ?

Have you got an example of how to use r.cost with two polygons in R with package spgrass6?

Thanks very much for your help.

Pierre
  • 435
  • 4
  • 14

1 Answers1

3

If the use of GRASS is not mandatory and sticking with R is sufficient, you should check the marmap package. Section 2.4 of the vignette (vignette("marmap")) is entitled:

2.4 Using bathymetric data for least-cost path analysis

The marmap package allows for computation of least-cost path constrained within a range of depth/altitude between any number of points. The two key functions here are trans.mat() to create a transition matrix similar to the cost-raster you mention. Then, lc.dist() computes the least-cost distance and allows to plot the path between points.

Detailed examples are provided in the marmap vignette.

Benoit
  • 1,154
  • 8
  • 11
  • Thank you very much Benoit. But I don't think that it is possible to get the cost of the path (cumulative cost of cells along the path) with the function `lc.dist` (and I don't want the distance or path). In addition, how can I to use this function to calculate the least-cost path between several polygons given that it is based on locations ? I have 1500 polygons in my landscape. Thanks very much for your help. – Pierre Sep 07 '14 at 20:47
  • I'm afraid you're right about `lc.dist()`. I have no knowledge of Grass so the only other thing I can think of is the `gdistance` package. The `marmap` functions `trans.mat()` and `lc.dist()` are based on functions from `gdistance`, so maybe you'll find an answer there. Best. – Benoit Sep 08 '14 at 16:08