3

I am trying to export a large feature collection from GEE. I realize that the Python API allows for this more easily than the Java does, but given a time constraint on my research, I'd like to see if I can extract the feature collection in pieces and then append the separate CSV files once exported.

I tried to use a filtering function to perform the task, one that I've seen used before with image collections. Here is a mini example of what I am trying to do

Given a feature collection of 10 spatial points called "points" I tried to create a new feature collection that includes only the first five points:

var points_chunk1 = points.filter(ee.Filter.rangeContains('system:index', 0, 5));

When I execute this function, I receive the following error: "An internal server error has occurred"

I am not sure why this code is not executing as expected. If you know more than I do about this issue, please advise on alternative approaches to splitting my sample, or on where the error in my code lurks.

Many thanks!

C. Ashley
  • 150
  • 1
  • 5

1 Answers1

5

system:index is actually ID given by GEE for the feature and it's not supposed to be used like index in an array. I think JS should be enough to export a large featurecollection but there is a way to do what you want to do without relying on system:index as that might not be consistent.

First, it would be a good idea to know the number of features you are dealing with. This is because generally when you use size().getInfo() for large feature collections, the UI can freeze and sometimes the tab becomes unresponsive. Here I have defined chunks and collectionSize. It should be defined in client side as we want to do Export within the loop which is not possible in server size loops. Within the loop, you can simply creating a subset of feature starting from different points by converting the features to list and changing the subset back to feature collection.

var chunk = 1000;
var collectionSize = 10000
for (var i = 0; i<collectionSize;i=i+chunk){
  var subset = ee.FeatureCollection(fc.toList(chunk, i));
  Export.table.toAsset(subset, "description", "/asset/id")
}
Nishanta Khanal
  • 316
  • 2
  • 4