I have land cover data from GEE (https://developers.google.com/earth-engine/datasets/catalog/ESA_GLOBCOVER_L4_200901_200912_V2_3) for specific countries. I would like to extract the values from the raster for certain regions. Specifically, I'd like to have a SpatialPolygonsDataFrame with one variable for each land cover class containing the area (absolute or relative) of that region covered in a specific class. My first idea was to transform the raster into a SpatialPolygons object and then calculate the intersection, but from what I read transforming rasters is quite inefficient and functions like extract should be used. How can I achieve what I want without transforming the raster?

edit: Sorry, I feel like title and text don't really match. My original idea was to convert the raster, then create a subset only containing areas with a certain values, then calculating intersections and distances. Is it possible to do this with the raster too?

  • You can do your analysis in GEE also, and just export the results. FYI.
    – Jon
    Commented Apr 12, 2019 at 17:07
  • I thought about that too (even though I don't know how), but in the end I need 100x100m² grids for certain countries and I think that's too much for GEE. Apart from that I need R for the analysis later on anyway.
    – tho_mi
    Commented Apr 12, 2019 at 17:09
  • You'd be surprised at what GEE will export! I don't use r so I don't think I can help, but it sounds like you want something like Zonal Statistics (QGIS) or rasterstats (python). These packages will return statistics of rasters within polygon boundaries. I am sure that there is a similar package for r.
    – Jon
    Commented Apr 12, 2019 at 19:27
  • I'd be very happy to use GEE for more than just downloading the raw data @Jon. Unfortunately my experience with GEE is limited and it seems to be much easier to find info on how to do this in R. But I'd be very grateful for GEE-related tips :)
    – tho_mi
    Commented Apr 13, 2019 at 2:56
  • You should have access to the GEE developer's forum--it's the best place to "google" for GEE-related questions and steal/borrow code. GEE's documentation also has a lot of helpful mini-tutorials; you should look at developers.google.com/earth-engine/reducers_reduce_regions, and more generally become familiar with "reducers".
    – Jon
    Commented Apr 13, 2019 at 17:13

1 Answer 1


It sounds like 'Extract by Mask' is what you need. Here's info... https://support.esri.com/en/technical-article/000013000

  • Thanks for the hint. Since I need it in R (or GEE) I'll google a bit.
    – tho_mi
    Commented Apr 13, 2019 at 3:01
  • Please edit your answer to include a summary, preferably with code, so that if the link goes 404 your answer will not follow the same fate.
    – Aaron
    Commented Sep 12, 2019 at 4:30

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.