4
var FC = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(120, 0), {'instrumentMode': ['IW', 'EW']})
  ]);
print('FC', FC);
Export.table.toAsset(FC)

When I tried to export this table, I confronted the error message, saying that "Unable to encode value 'instrumentMode' of feature 0: invalid type". I am confuse why making a list as a atribute does not work?

2 Answers 2

3

Look at this thread from the developer forum: https://groups.google.com/d/topic/google-earth-engine-developers/8E9o83kUtmk/discussion

EE is picky on the type of properties for assets. You probably have to stringify the list:

var FC = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(120, 0), {
    'instrumentMode': JSON.stringify(['IW', 'EW'])
  })
  ]);
print('FC', FC);
Export.table.toAsset(FC)

Then decode it when reading it:

var instrumentMode = ee.FeatureCollection('users/wiell/myExportTableTask')
  .first()
  .getString('instrumentMode')
  .decodeJSON()
print(instrumentMode)  
0

Use server ee.String.encodeJSON() instead of client JSON.stringify() to stringify any structured properties inside a map().

var list = ee.List(['IW', 'EW']);
var FC = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(120, 0), { "instrumentMode":ee.String.encodeJSON(list) })
  ]);
print('FC', FC);
Export.table.toAsset(FC)

It exports a feature containing prop {"instrumentMode":["IW","EW"]}

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.