TransWikia.com

Export NDVI values from chart as JSON in Google Earth Engine

Geographic Information Systems Asked on June 2, 2021

After filter OLI8 for a small area

var collectionFilter = ee.ImageCollection('LANDSAT/LC08/C01/T1_RT_TOA')
  .filterBounds(geometry)
  .filterMetadata('CLOUD_COVER','less_than',4)
  .map(app);
print(collectionFilter)

And add NDVI band

var app = function (image)
{
//indice de vegetação
var ndvi = image.normalizedDifference(['B5', 'B4']);
image=image.addBands (ndvi.rename('NDVI'));

  return image
}

I generate a chart using a click function and try to export as JSON format the values.

Map.onClick(function(lonlat){
  var pixel = ee.Geometry.Point([lonlat.lon, lonlat.lat])
  var collection = collectionFilter
    .select(
      ["NDVI"]
    )
    var options = {
        title : 'NDVI CHART VALUES'
      };

    var graph = (
    ui.Chart.image.series(
      collection,
      pixel,
      ee.Reducer.mean(), 
      30
    )
    .setOptions(options)
  );
      print(graph

  )

  Export.table.toDrive({
    collection: collection,
    description:  'exporting in json format each click',
    fileFormat: 'JSON'
  });

})

But doesnt work. How can I do this? Here is the link code

One Answer

The ui.Chart.image.series function works very well in visualizing rapidly pixel values at a certain point, but it outputs a chart which you cannot export using Export.table.toDrive. At the moment, you are trying to export a imageCollection as a table, what is probably not wat you want.

To get the NDVI values corresponding to the pixel [lat,lon] you clicked, you first have to use reduceRegion(s). Then you get the pixel information of a geometry.

  // make a feature collection (which you can export)
  var featureCollection = collection.map(function(image){
    return image.reduceRegions({collection: pixel, scale: 30, reducer: ee.Reducer.mean()})
    // Map over the new feature collection to add the system:time_start of the image
     .map(function(feat){
      return feat.set('system:time_start', image.get('system:time_start'));
    });
  }).flatten();
  print(featureCollection)

Then you can export that collection to you drive. Note that the format is GeoJSON and that you cannot use spaces in the name

  Export.table.toDrive({
    collection: featureCollection,
    description:  'exporting_in_json_format_each_click',
    fileFormat: 'GeoJSON'
  });

Note that I took the liberty to make you collection filter in such a way that it filters the collection on the point you clicked, so it should work anywhere around the world (as long as there are image present). Link code

Answered by Kuik on June 2, 2021

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