5

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?

1 Answer 1

6

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']})
1
  • Fantastic, worked perfectly, thanks! Jul 8, 2020 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.