7

I have a vector layer (polygon) and a raster layer. The raster layer holds values for height above bald earth in a field called "value". I'd like the vector layer to inherit either the mean or the mode values from raster cells falling within the boundaries of each polygon. I run this command in grass:

v.rast.stats nameofpolygon raster=nameofraster colprefix=height

The result is a polygon populated with all the fields you'd expect but containing all null values within these fields.

  • I did receive a warning that some polygons are missing centroids at the beginning of the output.
  • The raster and vector layers are within the same Grass Mapset and do occupy the same geographic space.
  • I did set the region to contain both features prior to running v.rast.stats

Thanks in advance for you help!

(2011/05/10)UPDATED DETAILS: I created an entirely new GRASS Location & Mapset; Loaded both my raster and polygon features to the same Mapset; Ran v.centroids on the polygons; Ran g.region.raster; Calculated univariate statistics (v.rast.stats) from the raster based on the vector; Double checked that the raster does actually contain values, and it does in a field titled "value". The statistics are still returning NULL values. I've tried this through GRASS, GRASS-gui, and QGIS gui.

2
  • I ran this same command (v.rast.stats) through the QGIS interface. The results were the same. I also again verified the raster and vector occupy the same geographic space and that the GRASS region contains the area in question. I'm going to add any missing centroids to the polygons through GRASS tools and try again to generate statistics.
    – Paul
    May 8, 2011 at 16:09
  • Note to self: Always check region limits...
    – nickves
    Nov 14, 2012 at 18:32

3 Answers 3

1

Try to change db.connect to SQLlite. I had the same problem and this worked for me.

0
1

Rasters have got a lot better in QGIS 1.7, I can run v.rast.stats from the GRASS Tools in the QGIS GUI. QGIS is much more friendly and if you have any inadvertent projection errors etc they are more obvious than is the case with GRASS. Despite your efforts to check, I suspect you have these sorts of problems. You should be able to point QGIS at the GRASS Mapset you have already created.

1
  • I have viewed my data in QGIS and also GRASS and the raster and vector do in fact occupy the same space. They are also within the same GRASS mapset.
    – Paul
    May 3, 2011 at 5:20
0

Did you have any luck with running v.rast.stats from within QGIS via the GRASS Plugin? At the dialog in that tool, at the top to the right of the dropdown for the raster map "name of raster map to calculate statistics from" there is a toggle button "use region of this map". Perhaps that helps. Also it was suggested to me to run "g.region raster" when trying to resolve the same problem in GRASS standalone, in the QGIS/GRASS plugin that command is available as g.region.multiple.raster. I believe this is worth a try.

ciao

1
  • Thanks for the QGIS advice. I did set the region based on the raster using the g.region command in GRASS as you suggest.
    – Paul
    May 8, 2011 at 14:56

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.