I need to extract pixel values from various ROIs (polygons). I need to extract the pixel values of each band, some properties contained in the attribute table of the polygon and I also need to calculate the % of the pixel covered by the polygon.

According to the documentation for ee.Image.sampleRegions there is no option to calculate coverage_fraction.

Can someone explain to me how to do this?

The exactextractr R package does allow this (https://github.com/isciences/exactextractr) but I would like to be able to implement it from GEE.

  • Hi, what shape of the polygon are you using? Is it something common/east to observe or is it more complicated tailor-made shape?
    – Meki21
    Mar 18, 2022 at 12:22
  • @Meki21 The shapes of each polygon are varied since they are agricultural parcels in my case.
    – sermomon
    Mar 18, 2022 at 12:29
  • Hmm well I am not exactly familiar with the in-built methods for GEE, but one way of checking whether a point is inside a polygon is to draw a vertical (or horizontal) line and see how many edges of a polygon it intersects. If it is odd, then its in a polygon. Taking this approach and generalise it, you can take a matrix of points and for each check how many intersections. Then you count the ones that are in and you have your answer:)
    – Meki21
    Mar 19, 2022 at 13:06

1 Answer 1


You can create a “coverage” image from any geometry by taking a constant image (or any image unmasked in the relevant area) and clipping it to the geometry, then using the clipped mask of that image: ee.Image(1).clip(region).mask(). Then, add that as a band to your original image and sampleRegions will include values from it:

var samples = image
    collection: ee.FeatureCollection([region]),

Runnable example

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.