TransWikia.com

Add feature id as a feature property in Google Earth Engine

Geographic Information Systems Asked on April 4, 2021

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.

One Answer

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',
});

Correct answer by Kevin Reid on April 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP