I have a FeatureCollection I made from a Polygon shapefile. I have fixed the geometries in qgis and should only be made out of many single polygons. But for some reasons some of my features are MultiPolygon and even some GeometryCollection which have linestrings and Polygons in the same features. I would like to filter my features to only keep geometry type equal to Polygon. ee.Filter.eq only seems to filter through the properties of the features. is there a filtering tool to filter through other parts of the features?

  • Can you share example data for your problem, preferably with a minimal working Earth Engine code to reproduce the issue. – Kersten Jan 7 at 8:38

You can get the type() of a feature's geometry(), set() it as a property on the feature and then filter() based on that property:

var collection = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point([-113.5, 40.1])),
  ee.Feature(ee.Geometry.Polygon([[[-109.4, 41.0],[-114.3, 38.5],[-109.5, 36.5]]]))

collection = collection.map(function(f) {
  return f.set('geo_type', f.geometry().type())

print(collection.filter(ee.Filter.eq('geo_type', 'Polygon')))

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.