1

Does anyone know if GEE sampleRegions() includes pixels that are on the edge of the polygon? I want to train a classifier with polygons, and want the classifier only to look at pixels that are completely inside by the polygon, ie not pixels that are touching the polygon perimeter.

For example, in this image, are pixels that are bisected by the polygon perimeter included in the call to sampleRegions?

polygon on raster

Here is an excerpt from the GEE guide, second code block on this page, that shows using the sampleRegions function in context of a simple supervised classification.

// Get the values for all pixels in each polygon in the training.
var training = image.sampleRegions({
    // Get the sample from the polygons FeatureCollection.
    collection: polygons,
    // Keep this list of properties from the polygons.
    properties: ['class'],
    // Set the scale to get Landsat pixels in the polygons.
    scale: 30
});

I didn't see anything in the API docs about this.

1 Answer 1

2

From the API docs:

Note that geometries will be snapped to pixel centers.

All pixels that have their centers within the collection input, are considered. You can easily check which pixels that are by setting the geometries argument to true and adding the points to the map.

// using sampleRegions
var sampleRegions = image.sampleRegions({
    collection: geometry,
    scale: 30,
    geometries: true
});

print('sampleRegions', sampleRegions)
Map.addLayer(image, {min: 0, max: 0.3})
Map.addLayer(sampleRegions)

See example code

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.