I have a FeatureCollection of polygons, I was wondering how I filter (remove) polygons that has the number of vertices smaller than a scalar.

1 Answer 1

// Find Features in a collection whose boundaries contain less than a given number of points.
// Based on example  https://code.earthengine.google.com/cbfc6e6fbe4b8f477d07283307269c12

var max_points = 200;

// Start with a feature collection - in this case US counties.
var counties = ee.FeatureCollection(

// Then  add a property called 'points' to each feature of the collection
// populate it with the number of points in the outer linear ring.
var countiesWithPoints = counties.map(function(f) {
  return f.set({ points  : ee.List(ee.List(ee.Feature(f).geometry().coordinates()).get(0)).length()});


var simpleCounties = countiesWithPoints.filterMetadata('points', 'less_than', max_points);
var complexCounties = countiesWithPoints.filterMetadata('points', 'greater_than', max_points);

Map.addLayer(simpleCounties, {color: '900000'});
Map.addLayer(complexCounties, {color: '008000'});

Map.setCenter(-119.7, 38.26, 7);

Try it: https://code.earthengine.google.com/7f814a69de1d90a0aed97977eb42969e

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.