Wednesday, 13 April 2016

google earth engine - What is the fastest/proper way to see if a FeatureCollection contains no Features


Take this code example, where mylabel is a ui.Label:


var mypt = ee.FeatureCollection(ee.Geometry.Point(Map.getCenter().coordinates()));

var states = ee.FeatureCollection('TIGER/2016/States');

var selectedstate = states.filterBounds(mypt);
var selstatename = selectedstate.first().get('NAME');
selstatename.evaluate(function(result) {

if (result) {
mylabel.setValue('State: ' + result.toString());
}
});

In the above simplified example, if the user has their map centered, say, over the ocean, then selectedstate will be a FeatureCollection with no Features in it. In that case, I can skip the following selstatename.first().get('NAME'); and selstatename.evaluate


I'm pretty sure there's got to be an easy way to check that, hopefully combined in the .filterBounds step so I don't have to send requests to the server twice, if that makes sense?


THIS IS ANSWERED HERE: How to get several property values at once so there is only one call to .`evaluate`




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...