I want to isolate the geometry of the ecoregion intersecting my ROI. However, using .filterBounds()
produces a multipolygon with segments that do not intersect my ROI. Instead, I only want the polygon that does intersect with my ROI.
So far I have managed to produce a list of individual polygons extracted from a single ee.Feature
with multipolygon geometry, but what I want is actually a ee.FeatureCollection
where each feature is a single polygon but keeps the properties of the original feature. This is what I have so far:
var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017');
var filteredEcoregion = ecoregions.filterBounds(ROI);
print('filteredEcoregion',filteredEcoregion);
Map.addLayer(filteredEcoregion,{},'Filtered ecoregion');
var multipoly2poly = function(multipoly){
var size = multipoly.coordinates().size();
var polylist = ee.List.sequence(0, size.add(-1), 1)
.map(function(listelem){
return ee.Geometry.Polygon(multipoly.coordinates().get(listelem));
});
return polylist;
};
var filteredEcoregion2 = multipoly2poly(filteredEcoregion.first().geometry());
print('filteredEcoregion2',filteredEcoregion2);
Link to code: https://code.earthengine.google.com/edf61201854677a12d3420248b1a138f