Sunday 13 January 2019

javascript - Google Earth Engine: Extract values from FeatureCollection as list


I'm trying to extract values from a FeatureCollection as a list. Here's some example code that I'm using in Earth Engine's code editor:


var viirs = 
ee.Image('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG/20120401').select('avg_rad');

var maineCounties =
ee.FeatureCollection('ft:1S4EB6319wWW2sWQDPhDvmSBIVrD3iEmCLYB7nMM').

filter(ee.Filter.eq('StateName', 'Maine'));

var maineMeansFeatures = viirs.reduceRegions({
collection: maineCounties,
reducer: ee.Reducer.mean(),
scale: 30
});

The "maineMeansFeatures" FeatureCollection has a column called "mean" -- I trying to extract the values in "mean" as a list (so, here, it'd be a list of 16 values -- one for each feature).


Any ideas on how to do this? (Note: I'm very new to javascript so I'm not that familiar with FeatureCollections).




Answer



Take a look at ee.FeatureCollection.aggregate_array:



Aggregates over a given property of the objects in a collection, calculating a list of all the values of the selected property.



So


maineMeansFeatures.aggregate_array("mean") 

should bring you an array of "means".


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...