0

I have a tabular asset in Google Earth Engine that has two features. To extract them one by one in a for-loop I had to introduce site_id property (column) and filter based on that value:

for (var i = 1; i < 2; i++) { 
  var feature = myAsset.filterMetadata('site_id', 'equals', i).first();
};

How can one extract one ee.Feature directly using the Feature Index which is present in the asset?

I am looking for an analogy of ee.FeatureCollection.first() but .second(), .third() etc enter image description here

1
  • 1
    use .toList() and then .get() – JonasV Sep 9 '20 at 20:08
2

Given that your table contains only two features, using a list is a good way to extract the individual features, and quite efficient.

var myAssetList = myAsset.toList(10);  // number must be at least 2 but can be a generous allowance
... use myAssetList.get(0) and myAssetList.get(1) ...

However, the order of features from assets is not guaranteed to be the same as the order in the table you uploaded (instead, it's based on a spatial index). Therefore, if you intend to do something different with the two features, and you want your results to be reproducible, it is actually a better idea to keep doing what you already have, with IDs you assigned yourself (site_id), because that way if you upload a new version of the table with changed points, the numbering of the features will still be predictable.

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.