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!


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 v.in.ogr, because as far a I know, v.external creates a read-only link to the dataset.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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