Google Earth Engine – How to Rename Columns in FeatureCollection

errorfeaturesgoogle-earth-engine

I have a Feature Collection I'm exporting as a csv. I used the reduceRegions function to get mean values of several different variables per region, and merged these into one large FeatureCollection. I simply want to chnage the column/property name for one of these. I found you could use the select function, but I have to rename one but still all the columns in as otherwise the selec function removes them from the FeatureCollection.

//var Dat = Dat.select(['mean', 'id'], ['SE_score', 'id']);

However, I'm getting this error

FeatureCollection (Error)
Error in map(ID=7_PB_IleDiamant_Lagoon): Feature.select: Selected a different number of properties (1) than names (2).

I think this is because I don't actually have data for some of these variables, they're just blank, which is fine for my export, but it means it's not allowing me to change the property name from 'mean' to 'SE_score'.

Are there other methods for changing column/property names you're aware of?

Best Answer

You could try:

var DataRenamed = Data.map(function(feat){
  return ee.Feature(feat.geometry(), { 
    SE_score: feat.get('mean'),
    id: feat.get('id')
  })
})

If you don't want or need the geometry, change feat.geometry() to null

Make sure that when you export the table, you set the selectors property. Otherwise you might have the change that a property with null values is not exported.

Export.table.toDrive({
           collection: DataRenamed, 
           description: 'NAME', 
           fileFormat: 'CSV', 
           selectors: ['SE_score', 'id']})
Related Question