0

I am trying to loop over my Feature Collection in steps of 500. My FeatureCollection contains over 30,000 features and I want to offset the features obtained by 500.

What I want (pseudocode):

for i in fc_step_of_500: 
fc[i:500+i]

Currently I am able to limit the collection like this

fc.limit(500)

But I want to offset on every iteration.

I have looked into iterate method, which essentially loops over every feature. But that is not what I want in this case.

1 Answer 1

2

Collections aren't designed for random access; any method you use to get there will severely limit the scalability of your code. That said, you can get to positional chunks by converting to a list, since toList has an offset argument.

collection.toList(count, offset)

A more scalable solution, if you don't mind them being non-contiguous, is to assign a random number to each feature and then iteratively filter to a subset that's approximately 500 items:

collection.randomColumn().filter('random < 0.15')

However, if you can explain why you want batches in the first place, there's almost certainly a better answer.

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.