0

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.

enter image description here

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

1 Answer 1

1

Actually it just was a matter of adjusting the function I was using :

var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017');

var filteredEcoregion = ecoregions.filterBounds(ROI);
print('filteredEcoregion',filteredEcoregion);
Map.addLayer(filteredEcoregion,{},'Filtered ecoregion');

var multipoly2poly = function(feature){
    var multipoly = feature.geometry();
    var size = multipoly.coordinates().size();
    var polylist = ee.List.sequence(0, size.add(-1), 1)
      .map(function(listelem){
          return ee.Feature(feature)
            .setGeometry(ee.Geometry.Polygon(multipoly.coordinates().get(listelem)));
      });
    return polylist;
};

var filteredEcoregion2 = ee.FeatureCollection(multipoly2poly(filteredEcoregion.first()));
print('filteredEcoregion2',filteredEcoregion2);

var filteredEcoregion3 = filteredEcoregion2.filterBounds(ROI)
Map.addLayer(filteredEcoregion3,{color:'blue'},'filteredEcoregion3')

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.