0

In GEE, user-generated feature collections are automatically assigned an id number. How do I create a property for each feature collection that stores the id ("system:index") as a property, such that when I export the feature collection as a shapefile, the ID remains?

I'm trying to execute this with the variable tiles_new before exporting the feature collection. Code is here.

3

system:index is itself a property; in principle, you don't need to add another one, just to ask for it.

var collection = ee.FeatureCollection([
  ee.Feature(null, {'foo': 'a'}),
  ee.Feature(null, {'foo': 'b'}),
]);

Export.table.toDrive({
  collection: collection,
  selectors: ['system:index', 'foo'],
  fileFormat: 'csv',
  description: 'id_demo',
});

This script will export a file that includes the automatically assigned value:

system:index,foo
0,a
1,b

However, for an export to shapefile, we have column name length and format restrictions (and also need to have some geometry rather than null, in this demo). So, you can rename the property with .select():

var collection = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(1, 1), {'foo': 'a'}),
  ee.Feature(ee.Geometry.Point(2, 2), {'foo': 'b'}),
]);

Export.table.toDrive({
  collection: collection.select(['system:index', 'foo'], ['id', 'foo']),
  fileFormat: 'shp',
  description: 'id_demo',
});
1
  • Thank you for your help. Using "select" when exporting worked, but if I didn't rename the variables, it did not export the id. Just thought I would point that out for anyone struggling with this in the future.
    – C. Ashley
    Dec 3 '20 at 23:27

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.