least cost path file conversion

Rod Paterson rgp at aberfoyle.oz.au
Thu Apr 25 08:00:00 EDT 1996


Paul W. Box writes:
> 
> I would like to know if there is a straightforward way to do this.  I
> would like to take a least-cost path route created by r.drain, and
> export the results to a simulation in the form of a list of cells or
> lat-long coordinates.  For example, if r.drain is used to calculate the
> least cost path between two cells, then I would like to get a list of
> the individual cells that the path crosses in the order that they're
> crossed.

 Take the raster output by r.drain in which the least cost path will be 1's
 and all other cells will be zero's and run:
 'r.stats -1 -g -x -z input=drainfile fs=, output=outfile'

Note: -1 outputs the data for each cell one per line
      -g prints the grid coords east,north for each cell
      -x prints the x and y (column and row) values for each cell
      -z zero cells will not be reported
      fs is the file column separator you need ie. , | or ' ' etc
      outfile will contain the locations one per line but I don't
              think they will be in path order. If the path does
              not turn back on itself ie either N or E always increasing
              or decreasing then a sort will get them in order.

 If this is not true then you will have to write a little?
 routine that given the start pixel coord traverses the list looking for
 the neighbouring/nearest pixel in the list etc.

 If you just need the actual path then you could run r.poly on the 'drainfile'
 and get back a vector file of the least cost path.

        regards
        Rod Paterson
        Aberfoyle Resources Ltd
        Level 31
        525 Collins Street
        Melbourne Vic., 3000

        Phone: 61-3-92706666
        Fax:   61-3-92706699
        Email: rgp at aberfoyle.oz.au





      






More information about the grass-dev mailing list