Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am now working in grass and I want to extract raster values from several images to a shapefile. I have already created the columns in the .shp where the raster values will be stored but I am facing difficulties on how will I make the loop...

What I want is to extract the values of image_1 to column_a, values of image_2 to column_b etc etc... The problem that I have is that I can't make the loop for two variables (raster image and shapefile column) together... It must be easy but I am new in grass and bash in general as you must have already understood.

The command that I used is "v.what.rast"

Thank you!

share|improve this question
up vote 2 down vote accepted

You can create a loop to iterate through your data using v.what.rast. If you update your field names with an integer (e.g. column_1, column_2 ..), the following loop should work.

    for image in `g.mlist type=rast patt=*image_regexp*`
      v.what.rast vector=target_vector raster=$image column=column_$1

I'm almost certain that you'll need to import your Shp file into the GRASS native vector format using, because as far a I know, v.external creates a read-only link to the dataset.

share|improve this answer
Yes! This is the answer! Thank you very much! – Vilen Nov 12 '12 at 11:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.