1

I have recently moved to using GRASS for GIS within R and I would like to extract values of a raster dataset that overlap with polygons (i.e. something like 'extract' in the raster package of R).

I can perform my task for spatial points as follows:

execGRASS("r.what", flags="n", map="temperatureRaster", Sys_input=paste(x, y, site, sep=' '), separator=",", intern=TRUE)

However, I have spatial polygons not spatial points. Eventually, I would like to calculate a mean value for all raster cells whose centroid overlaps with each spatial polygon.

1 Answer 1

2

I would suggest using the GRASS module v.rast.stats as it "calculates univariate statistics from a raster map based on a vector map and uploads statistics to new attribute columns".

2
  • Yes, that looks like what I need. However, I think I would first like to get the vector map of all the points (raster cell centroids) inside each of my polygons. Do you know how I could do that?
    – tsutsume
    Commented Jan 16, 2018 at 11:17
  • @tsutsume v.rast.stats is the most straightforward way to get data for the raster cells within each polygon, as you described in your question. But if you need vector points for each raster cell, you could start by using r.to.vect type=point, then use v.overlay to relate the points to the areas. Commented Jun 30, 2021 at 18:22

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.