0

Does any one know, how to export a single feature out of featureCollection in Google Earth Engine?

I am using below code to export every features separately. The fetureCollection has 33 different features which represents different 33 geometry of regions. I want to get those geometry separately as shapefile.

The blow code gives me an error in task section: Error: Invalid argument: 'collection' must be a FeatureCollection. So, tried to get the sub_region(in the code) as ee.FeatureCollection instead of ee.Feature , but I am still getting same error.

var refReg = ee.FeatureCollection("users/username/referenceRegions");

var referenceRegions={
  0:'NTP',1:'STP',2:'ETP',3:'WIO',4:'CAR',5:'NAU',6:'NEB',7:'NEU',8:'SAF',
  9:'SAH',10:'SAU',11:'SSA',12:'TIB',13:'WAF',14:'WAS',15:'WNA',16:'WSA',
  17:'ALA',18:'AMZ',19:'CAM',20:'CAS',21:'CEU',22:'CGI',23:'CNA',24:'EAF',
  25:'EAS',26:'ENA',27:'MED',28:'NAS',29:'ARC',30:'SAS',31:'SEA',32:'ANT'
};

var region_list = refReg.toList(refReg.size());

var reg_size = refReg.size().getInfo();

for (var i = 0; i<reg_size;i++){
   var sub_region = ee.Feature(region_list.get(i));

   Export.table.toDrive({
   collection: sub_region,
   description:referenceRegions[i],
   folder:"GEE_Features",
   fileFormat: "SHP",
   })
}

If you see the below image, the FeatureCollection refReg has all these 33 regions, I want these regions to export individually.

enter image description here

Thanks for the help!! :)

1 Answer 1

2

Your asset ID doesn't look correct, so I cannot try it. But just by looking at it, everything look OK except for when you pass sub_region as your Export.table.toDrive() collection. That property must be a feature collection. Try with this:

Export.table.toDrive({
  collection: ee.FeatureCollection([sub_region]),
  description: referenceRegions[i],
  folder: "GEE_Features",
  fileFormat: "SHP",
})
1
  • Thanks Daniel, it worked :)
    – terraCoder
    May 13, 2020 at 15:03

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.