1

How do I remove a property from a Feature (or FeatureCollection), by only specifying the name of the properties I want to remove? I know I can "remove" by selecting only properties I want, but in my case it is quite cumbersome...

For minimal example in code below (see also link), how to remove property color?

var features = [
  ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen', color: "a"}),
  ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet', color: "a"})
];

// Create a FeatureCollection from the list and print it.
var FC = ee.FeatureCollection(features);
print(FC);


// Now I want to remove property color in each feature?
3

You have to make a function to do that and then apply it to the collection:

var features = [
  ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {name: 'Voronoi', color: "a"}),
  ee.Feature(ee.Geometry.Point(-73.96, 40.781), {
    name: 'Thiessen', 
    color: "a"
  }),
  ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {
    name: 'Dirichlet', 
    color: "a"
  })
];

// Create a FeatureCollection from the list and print it.
var FC = ee.FeatureCollection(features);
print(FC);

// Generic Function to remove a property from a feature
var removeProperty = function(feat, property) {
  var properties = feat.propertyNames()
  var selectProperties = properties.filter(ee.Filter.neq('item', property))
  return feat.select(selectProperties)
}

// remove property color in each feature
var newFC = FC.map(function(feat) {
  return removeProperty(feat, 'color')
})

print(newFC)

link

  • great, exactly what I needed, thanks! And in case one wants to remove a list of properties, it seems like ee.Filter.inList('item', property).not() would do the trick!? – Matifou May 5 at 17:23
  • also, any idea why in the JS editor, when printing result, we have now FeatureCollection (3 elements, 0 columns)? – Matifou May 5 at 18:14

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.