TransWikia.com

Create Time Series Chart of NDVI (based on Landsat 5) of a National Park in Germany with Google Earth Engine

Geographic Information Systems Asked by ChrissiLissi on October 1, 2020

So this is my code so far:

My Questions:
How do I name the title and x-axis and y-axis? It isn´t working with
.setOptions({title: 'NDVI Bayrischer Wald Landsat 5 1984 - 2013'}) unfortunately.

How do I mask all Landsat 5 Images over 20% Cloud Cover?

To get a linear trend for the meanNDVI I wanted to do a regression in GGE.

Could someone could give me a hint or two on how to do it?

//Import the shapefile boundary
//Add the boundary as a layer 
var BayrischerWald =
   table;
  Map.addLayer(BayrischerWald)

var landsat5Toa = ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA')
    .select('B[1-5]');
    
var sorted = landsat5Toa.sort('CLOUD_COVER');


// Get the median over time, in each band, in each pixel.
var median = landsat5Toa.median();

// Make a handy variable of visualization parameters.
var visParams = {bands: ['B4', 'B3', 'B2'], max: 0.3};

// Display the median composite.
Map.addLayer(median, visParams, 'median');

// Load or import the Hansen et al. forest change dataset.
var hansenImage = ee.Image('UMD/hansen/global_forest_change_2015');

// Select the land/water mask.
var datamask = hansenImage.select('datamask');

// Create a binary mask.
var mask = datamask.eq(1);

// Update the composite mask with the water mask.
var maskedComposite = median.updateMask(mask);

Map.addLayer(maskedComposite, visParams, 'masked');

// Make a water image out of the mask.
var water = mask.not();

// Mask water with itself to mask all the zeros (non-water).
water = water.mask(water);

// Make an image collection of visualization images.
var mosaic = ee.ImageCollection([
  median.visualize(visParams),
  water.visualize({palette: '000044'}),
]).mosaic();

// Display the mosaic.
Map.addLayer(mosaic, {}, 'custom mosaic');

// Get one Image
var image = ee.Image(
  landsat5Toa.filterBounds(table)
    .sort('CLOUD_COVER')
    .first()
);

// Compute the Normalized Difference Vegetation Index (NDVI).
var nir = image.select('B5');
var red = image.select('B4');
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');

// Display the result.
Map.centerObject(image, 9);
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(ndvi, ndviParams, 'NDVI image');
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
  return image.addBands(ndvi);
};

// Map a function over the Landsat 5 TOA collection to add an NDVI band.
var withNDVI = landsat5Toa.map(function(image) {
  var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
  return image.addBands(ndvi);
});


// Create an image time series chart.
var chart = ui.Chart.image.series({
  imageCollection: withNDVI.select('NDVI'),
  region: BayrischerWald,
  reducer: ee.Reducer.mean(),
  scale: 200
});

// Add the chart to the map.
chart.style().set({
  position: 'bottom-right',
  width: '1000px',
  height: '300px'
})
Map.add(chart);

// Create a label on the map.
var label = ui.Label('Click a point on the chart to show the image for that date.');
Map.add(label);

// When the chart is clicked, update the map and label.
chart.onClick(function(xValue, yValue, seriesName) {
  if (!xValue) return;  // Selection was cleared.

  // Show the image for the clicked date.
  var equalDate = ee.Filter.equals('system:time_start', xValue);
  var image = ee.Image(landsat5Toa.filter(equalDate).first());
  var l8Layer = ui.Map.Layer(image, {
    gamma: 1.3,
    min: 0,
    max: 0.3,
    bands: ['B4', 'B3', 'B2']
  });
  Map.layers().reset([l8Layer, sfLayer]);

  // Show a label with the date on the map.
  label.setValue((new Date(xValue)).toUTCString());
});

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