[GRASS-user] How to extract multiple raster values to points

Margherita Di Leo diregola at gmail.com
Fri Mar 23 12:39:55 EDT 2012


Hi,

On Fri, Mar 23, 2012 at 5:06 PM, <Raphael.Viscarra-Rossel at csiro.au> wrote:

> Hello,
> I wonder if there is a way to extract/sample (eg using nearest neighbour)
> the values from multiple rasters that correspond to a set of to vector
> points into a table.
> I could find a way to do this for one raster, but not for multiple
> rasters. Has anyone done this in GRASS?
>

Not sure if i got what you mean to do. With r.what you can extract the
characteristics from multiple rasters, given the coordinates of the points
you are interested in. If you have multiple points, you can apply r.what
iteratively using a simple script, i.e.:

#! /usr/bin/python

import os, sys
from glob import glob
import grass.script as grass

topidx = sys.argv[1]
accMFD = sys.argv[2]

fpath = 'your/path/to/coordinates/file'

# coordinates is a txt file in which coordinates are stored
coord = open( os.path.join(fpath, 'coordinates'), 'r').readlines()
pairs = []

for line in coord:
    line = line.strip()
    x, y = line.split('\t')
    pairs.append( x + "," + y )

r_what = grass.read_command('r.what', input = 'topidx,accMFD', east_north =
pairs)

# create a new file output
fout = open( os.path.join(fpath, 'output'), 'w')
fout.write(r_what)
fout.close()

Hope this helps,
madi

-- 
Ing. Margherita Di Leo, Ph.D.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20120323/d251a0dd/attachment.html


More information about the grass-user mailing list