0

I'm working with Google Earth Engine. I need to convert the image pixels into a featureCollection. I'm using the reduceToVectors() function however, this function combines the pixels with the same value into a single polygon.

How can I avoid this aggregation?

Script here: https://code.earthengine.google.com/67d3858ab1cd2ee443054e657eb77aed

// var geometry --> draw your own geometry
var s2Col = ee.ImageCollection("COPERNICUS/S2_SR")
    .filter(ee.Filter.inList('MGRS_TILE', ['30SYJ']))
    .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 75)
    .filterDate('2019-05-10', '2019-05-12');

var s2Image = s2Col.first();

var imageClip = s2Image.clip(geometry).select('B4');

var imagePixCol = imageClip.reduceToVectors({scale:10});
print(imagePixCol);

Map.addLayer(imagePixCol);

1 Answer 1

1

You can use image.sample() for this.

But why are you converting pixels to a featureCollection in the first place. (This is often a sign you're doing something improper).

2
  • The reason to convert the pixels into a featureCollection of polygons is that I need to calculate the percentage of each pixel covered by a polygon (in my case an agricultural parcel). This allows me to filter full pixels inside a parcel, or pixels covered >75%, >50%, etc. This functionality is implemented in some software packages such as the R package exactextractr. I take this opportunity to pass on to you the suggestion to implement this new feature in GEE.
    – sermomon
    Oct 14, 2022 at 18:27
  • You don't need to convert to vector to do that, you can do it entirely in raster space (and much faster), by rasterizing the polygon. You'll just need to do the summation at a much higher resolution. Oct 16, 2022 at 12:20

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.