Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

1 Answer 1

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.

    i=0
    for image in `g.mlist type=rast patt=*image_regexp*`
    do
      v.what.rast vector=target_vector raster=$image column=column_$1
      $((i++))
   done

I'm almost certain that you'll need to import your Shp file into the GRASS native vector format using v.in.ogr, 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

 
discard

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.