TransWikia.com

Can't convert a computed Geometry to GeoJSON. Use evaluate() instead

Geographic Information Systems Asked on June 6, 2021

This is my code, and it generates this error. I’m wondering how to fix it.

Can't convert a computed Geometry to GeoJSON. Use evaluate() instead.
    in createNDVIComposite(), line 30
    in <global>, line 57
    in <global>, line 59


var roi = roi.geometry();
//==================================//
// LANDSAT NDVI COMPOSITE CREATION //
//==================================//

// NDVI Functions
/*These 2 functions are used to calculate the NDVI for Landsat 5/7 and Landsat 8, respectively.*/
var getNDVI57 = function(image) {
  var ndvi = image.normalizedDifference(['B4', 'B3']);
  return(ndvi);  
};
var getNDVI8 = function(image){
  var ndvi = image.normalizedDifference(['B5', 'B4']);
  return(ndvi); 
 
};


// Main function
var createNDVIComposite = function(){
  var yearrangeStart = 1999;
  var yearrangeStop = 2018;
  var imgList = [];
  for(var loopYear = yearrangeStart; loopYear <= yearrangeStop; loopYear +=1){
    var start = ee.Date.fromYMD(loopYear, 1, 1);
    var end = ee.Date.fromYMD(loopYear, 12, 31);
  
    //Landsat 8
    var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR") 
      .filterBounds(roi) 
      .filterDate(start, end) 
      .filterMetadata('CLOUD_COVER', 'less_than', 80) 
      .map(getNDVI8);
    
    //Landsat7
    var l7 = ee.ImageCollection("LANDSAT/LE07/C01/T1_SR") 
      .filterBounds(roi) 
      .filterDate(start, end) 
      .filterMetadata('CLOUD_COVER', 'less_than', 80) 
      .map(getNDVI57);
    
    //Landsat5
    var l5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR")
      .filterBounds(roi)
      .filterDate(start, end)
      .filterMetadata('CLOUD_COVER', 'less_than', 80)
      .map(getNDVI57);

    //Merge collections
    var mergedCollection = ee.ImageCollection(l8.merge(l7).merge(l5))
                            .reduce(ee.Reducer.median())
                            .reduce(ee.Reducer.percentile([90]));

    var finalOutput = mergedCollection.clip(roi).rename(loopYear.toString());

    imgList.push(finalOutput);
    //Generate filename for export
    var filename = ("Annual_NDVI_"+roi+"_").concat(loopYear.toString());
  }
 
  // Visualization parameters.
  //var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
  var args = {
    crs:'EPSG:3857',
    dimensions: '300',
    region: roi,
    min: -1, 
    max: 1, 
    //palatte: [ndviParams],
    palette: ['blue', 'white','green',' red'],
    framesPerSecond: 2,
  };

  var yearImgCol = ee.ImageCollection.fromImages(imgList);
  
  var thumb = ui.Thumbnail({
    // Specifying a collection for "image" animates the sequence of images.
    image: yearImgCol,
    params: args,
    style: {
      position: 'bottom-right',
      width: '320px'
    }});
  Map.add(thumb);

}

//print(ui.Thumbnail(Class.select('classificacao'), videoArgs));

//-----------------------------------// 
// MAIN FUNCTION EXECUTION // 
//-----------------------------------// 
var comp = createNDVIComposite();

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP