1

I have upload a kml file including main metropolitans in us as a fusion table, I can print the featurecollection but cann't visualize it in code editor.What's wrong with my code?

var fc = ee.FeatureCollection('ft:1Eii75QFBlQcYILLBFsU6zv9LhgJLa8FPHNGSZijQ')

Map.addLayer(fc, {}, 'metro');


print('fc',fc)

2 Answers 2

5

You can specify the property to use as the geometry by passing it as the second parameter to ee.FeatureCollection:

var fc = ee.FeatureCollection('ft:1Eii75QFBlQcYILLBFsU6zv9LhgJLa8FPHNGSZijQ', "geometry")
1
  • Awesome! Brief answer makes a big difference!
    – Jsun
    Commented Feb 21, 2019 at 17:39
1

Somehow, you uploaded that KML file with the geometry set as a property of the feature, instead of the actual geometry of that feature. With this code, you can get the geometry of the property of each feature, return each feature with it's other properties and the geometry set as geometry:

var withGeometry = fc.map(function(feat){
  var geom = ee.Geometry(feat.get('geometry'));
  var propNames = feat.propertyNames().remove('geometry');
  var props = feat.toDictionary(propNames);
  return ee.Feature(geom, props);
});
print(withGeometry)
Map.addLayer(withGeometry.draw('red'),{}, 'feat collection')

Link

0

Your Answer

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

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