3

I am using a very detailed 30 m x 30 m raster on deforestation (found here: https://storage.googleapis.com/earthenginepartners-hansen/GFC-2020-v1.8/download.html), I want to do all my analysis at this 30m x 30m grid level, however, I also want to know which underlying administrative region/state does this grid fall within.

My first try was to convert the raster to a polygon and then do a spatial join with a shapefile that contains information on the administrative boundaries. In QGIS this would be polygonzing or in R using the stars package and vectorizing a raster object to an sf object - however in QGIS it takes over 2 hours to barely reach 10% while polygonizing and in R I get "vector memory exhausted (limit reached?)". I understand the raster is very detailed so this may not be the most efficient way, so is there any other way to do a grid analysis and attach this information from the country shapefile?

1
  • Can you clarify what you are trying to achieve? Could you do your analysis on the raster then use zonal statistics to summarize what is going on within each administrative unit? With that approach look at zonal statistics under processing on QGIS or terra::extract() or stars::aggregate() on R. Sep 26 at 20:38

1 Answer 1

0

Clip raster by polygons (administrative units)

There is a reason why such analysis are done using raster, not vector layers. For better performance, do all the analysis on your raster layer. Be sure to clip your raster layer to your area of interest before doing your analysis: Menu Raster / Extraction / Clip Raster by Mask layer. This way, the raster already represents administrative units.

This is probably the faster and easier solution than using a grid.


Using point grid

If you still want to use a vector grid, do all the analysis on your raster layer and afterwards "join" the results to a point layer - points representing the centroid of each raster pixel. The points are easy to connect to administrative boundaries.

  1. Create a point grid using Menu Vector / Research Tools / Create Grid, using the extent of the raster layer, the same spacing as pixel size and the same CRS as the raster.

  2. When you have the points, get the raster values of each output of the raster geoprocessing by creating a new attribute with Field calculator and this expression:

    raster_value('raster',1,$geometry)

    Adapt these values:

    • raster ist the name of the raster layer
    • 1 is the number of the corresponding band
3
  • Thank you for your answer, I agree with you the analysis should be done at the raster level itself. I apologize I forgot to add this information in the question but I did in fact try to create a grid of points with the same spacing as pixels of the raster, but that too was taking a very very long time, after 2-3 hours it was not even half way done (Maybe it's my laptop, I'm not sure what's going on here). Even to start doing analysis on my raster, I need information on which states these pixels fall within. Something like a spatial join between the raster and shapefile.
    – Neha
    Dec 17, 2021 at 18:08
  • What about the Clip Raster by Mask layer part of the answer? Ckip the raster by the polygon(s) representing administrative regions. Then there is no need to convert to vector grids.
    – Babel
    Dec 17, 2021 at 18:39
  • Oh, that's an excellent suggestion, break down the country shapefile into small administrative polygons and then clip raster by these. I will try this. Thank you!
    – Neha
    Dec 17, 2021 at 19:19

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.