0

I have a raster map with trees in grass (1 and NULL value) for 6m resolution. I would like to aggregate this data in a grid with a resolution of 250m.

For that I have created a grid with v.mkgrid and using v.rast.stats I what count pixel for each grid cell.

It works perfectly in 50 min for a grid of 81323 cells.

To compare with MODIS data I have used R and create a grid with the exact extend and resolution of my MODIS value

grid <- raster(extent(one.ym))
res(grid) <- res(one.ym)[1]
proj4string(grid)<-proj4string(one.ym)
gridpolygon <- rasterToPolygons(grid)
writeOGR(obj = gridpolygon,dsn="/home/user/",layer="mygrid_modis.shp", driver = "ESRI Shapefile", overwrite_layer = T

Once my grid imported in GRASS-GIS I run v.rast.stats but I spend 6h and it is still running.

What's the difference between shapefile grid and Grid from v.mkgrid? How can I improve my shapefile grid time?

By the way, I have created my grid in grass72 using r.to.vect on my landsat raster. It doesn't make a difference in CPU time. In both case I have defined the region size and resolution on my raster.

1

Be sure to set the computational region to the raster map prior to the call of v.rast.stats. For this, see also the Wiki: https://grasswiki.osgeo.org/wiki/R_statistics/rgrass7#Querying_maps

You could also use r.in.xyz if you need to just count occurrences with "method=n". It is super-fast. The original data first write out with e.g. r.out.xyz.

| improve this answer | |
  • Thank you for the resource on computational region, but using r.to.vect on my landsat raster I have a grid with good extent... and it does not make faster the v.rast.stats function. I don't understand this CPU difference! – delaye Apr 25 '17 at 8:32
  • Well, v.rast.stats calculates univariate statistics from a raster map based on a vector map and uploads statistics to new attribute columns. Hence a lot of database traffic is involved. But I'll edit my answer for another idea. – markusN Apr 25 '17 at 18:17
  • Thank you ! to stay concerned :-) So using your edit, can just : 1) create vector points from my tree raster layer, 2) shift from a 6 m resolution region to 250m and 3) ask r.in.xyz to count points ? Anyway it's still strange this difference of cpu calculation time between these two use of v.rast.stats... something like a factor 10 (40 min with a grid from v.mkgrid and 400 min for my grid created with r.to.vect) – delaye Apr 26 '17 at 9:42
  • Concerning the speed of v.rast.stats: perhaps try with a different DB backend. I suppose that you use SQLite at time (check with db.connect -p), you may try PostgreSQL. Please note that v.rast.stats and r.to.vect do different things, so the performance cannot be the same. – markusN Apr 26 '17 at 18:50

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.