Obtaining time series of water extents per plot using landsat NDWI data available on GEE

Geographic Information Systems Asked by Batbr on December 5, 2020

I wanted to obtain a monthly time series estimate of the water surface for each of 67 survey plots (500m circles). However, I could not figure out how to correctly code this in the google earth engine. My code below does not seem to count the number of water pixels per plot.

Here is my code link:

// // Load from Fusion table
var surveyPlots = ee.FeatureCollection(table, 'geometry');

// Create water mask
var water = function(image) {
  return image.updateMask(;

// Load a dataset.
var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_8DAY_NDWI')

var bandName = ee.Image(dataset.first()).bandNames().get(0);

var startDate = ee.Date('2014-04-01'); // set analysis start time
var endDate = ee.Date('2014-10-01'); // set analysis end time

// calculate the number of months to process
var nMonths = ee.Number(endDate.difference(startDate,'month')).round();

// get a list of time strings to pass into a dictionary later on
var monList = ee.List(ee.List.sequence(0,nMonths).map(function (n){
  return startDate.advance(n,'month').format('YYYMMdd');

var result ={
  // map over each month
  var timeSeries = ee.List.sequence(0,nMonths).map(function (n){
    // calculate the offset from startDate
    var ini = startDate.advance(n,'month');
    // advance just one month
    var end = ini.advance(1,'month');
    // filter and reduce
    var data = dataset.filterDate(ini,end).median().reduceRegion({
      reducer: ee.Reducer.count(),
      geometry: feature.geometry(),
      scale: 30
    // get the value and check that it has data
    var val = ee.Number(data.get(bandName));
    val = ee.Number(ee.Algorithms.If(val,val,-999));
    // return value with a time key
    return val;
// create new dictionary with date strings and values
  var timeDict = ee.Dictionary.fromLists(monList,ee.List(timeSeries));
  // return feature with a timeseries property and results
  return feature.set(timeDict);

// print to see if it is doing what we expect...

// drop .geo column
var polyOut =['.*'],null,false);

// Export the data to a table for further analysis

Add your own answers!

Ask a Question

Get help from others!

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