0

I'm running the LandTrendr algorithm in GEE over multiple points of interest, which leaves me with a FeatureCollection having a list of lists in one the properties for every feature. Out if this list of lists called LandTrendr I need to know whether the second-to-last element of list #3, is equal to 1 (See orange arrow in the picture). How can I index/query this LandTrendr property to get the desired element?

I have tried many strategies to reach this index, but I don't get anyfurther than isolating the FeatureCollection to a single Feature having only the LandTrendr property left (using .first().select(['LandTrendr'])). At this point it refuses to convert into an array or a list using .toList() or .toArray().

FeatureCollection with List of Lists. Orange arrow indicates the desired index position to be retrieved.

I actually wanted to share the FeatureCollection as an Asset, but somehow GEE didn't let me, so I'll be sharing the whole code below.

Code walk-through: After defining the parameters, building the input time-series, and running the algorithm, I reduce the input back to the original points of interest, as defined by this question. Now, the second-to-last element of list no.3 in the LandTrendr property is the desired index to be retrieved.

// #########################
// # Define inputs and parameters 
// #########################

//points of interest 
var myPoints = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(-60,-20), {'id': 0}),
  ee.Feature(ee.Geometry.Point(140,-20), {'id': 1}),
  ee.Feature(ee.Geometry.Point(-70,10), {'id': 2}),
  ee.Feature(ee.Geometry.Point(80,40), {'id': 3}),
  ee.Feature(ee.Geometry.Point(10,50), {'id': 4}),
  ee.Feature(ee.Geometry.Point(20, -10), {'id': 5})
]);

// load the LandTrendr.js module
var ltgee = require('users/emaprlab/public:Modules/LandTrendr.js');

// define collection parameters
var startYear = 2005;
var endYear = 2016;
var startDay = '06-01'; // MM-DD start summer North Hem 
var endDay = '08-31'; // MM-DD end summer North Hem
var index = 'NDVI';
var ftvList = [];
var maskThese = ['cloud', 'shadow', 'snow'];

// define landtrendr parameters
var runParams = { 
  maxSegments:            6,
  spikeThreshold:         0.9,
  vertexCountOvershoot:   3,
  preventOneYearRecovery: true,
  recoveryThreshold:      0.25,
  pvalThreshold:          0.05,
  bestModelProportion:    0.75,
  minObservationsNeeded:  6
};

// #################
// # Prepare Input Time-Series
// #################

// Make annual surface reflection collection 
var annualSRcol = ltgee.buildSRcollection(startYear, endYear, startDay, endDay, myPoints, maskThese);

// Make annual LandTrendr collection with 1-observation per year
var annualLTcol = ltgee.buildLTcollection(annualSRcol, index, ftvList);

// add preprocessed time-series to the parameters for the algorithm
runParams.timeSeries = annualLTcol; 

// ################
// # run LandTrendr
// ################
var LTresult = ee.Algorithms.TemporalSegmentation.LandTrendr(runParams);

// Reduce the LandTrendr result by the aoi (myPoints). Use ee.Reducer.first() to select
// the pixel that intersects the point.
var ltPoints = LTresult.reduceRegions({
  collection: myPoints,
  reducer: ee.Reducer.first(),
  scale: 30
});

print(ltPoints);
1

I believe that what you want is this:

ltPoints.toList(ltPoints.size())
        .map(function(feature){
               return ee.Feature(feature).getArray('LandTrendr').get([3,-2])
             })

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.