1

I am trying to generate a ground truth feature collection to do some machine learning. I have a shapefile that contains one class of my ground truth. and I am manually creating a second feature collection that contains the second class.

My shapefile contains 11 columns and 128 features. I would like to delete all the columns that are currently in the shapefile attribute table and add a column containing a constant number. This would allow me to later merge the shapefile with the feature collection I created to obtain a training set I can use for machine learning.

Is there a way to do this in GEE or should I edit the shapefile in QGIS and import it again?

1 Answer 1

3

To remove all the properties, use select() with an empty list of property names. Then you can add the class property and merge it with other collections, for classification or export:

// Replace these two collections with your uploaded shapefiles
var input_1 = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(100, 10), { 'irrelevant': 123, }),
]);
var input_2 = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(100, 20), { 'irrelevant': 456, }),
]);

var mergedWithClassesAdded =
  input_1.map(function (feature) {
    return feature.select([]).set('class', 1);
  })
  .merge(
    input_2.map(function (feature) {
      return feature.select([]).set('class', 2);
    })
  );

print(mergedWithClassesAdded);
1

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.