5

I am aware that there are tools available in QGIS for sampling a raster at any given point from a shapefile.

The methods I've tried are:

  • Point sampling tool plugin
  • Raster analysis > sample raster values
  • Saga > Raster Values to Points

They all generate an output file, which contains the points and the altitude as an attribute (I always sample from a DEM).

Now, my workflow involves the constant change of a point shapefile, and then getting the Z values (by sampling a DEM), so end up generating a lot of trash files. Further, this implies also that I have to keep changing the path in my code for the new updated point file with the new altitudes.

Is there a tool I could use to sample a raster by just updating an attribute in the attribute table of the point shapefile?

0

1 Answer 1

10

You can use the raster_value function in an expression in the Field Calculator to update a field in your point layer with the pixel value from an underlying raster:

raster_value( 'DEM', 1,  $geometry )

Where 'DEM' is the name of your raster layer, and 1 is the band number.

You could also use this expression in a virtual field so that the value will be updated on the fly if you add or edit point features.

2
  • 2
    Works like a charm, thank you! Commented Oct 28, 2022 at 10:32
  • 1
    @LaCordillera, no problem :-)
    – Ben W
    Commented Oct 28, 2022 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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