TransWikia.com

Extract water bodies using Sentinel 2 - Google Earth Engine

Geographic Information Systems Asked by questionqueen on January 5, 2021

I would like to extract water bodies (a lake to be specific) from Sentinel 2 images on Google Earth Engine. I know the Global Surface Water Explorer has pixel data on water-no water, but for my study area, the amount of usable images is very limited. Thus I wanted to branch out to different products.

To be specific I would like to create a time series with the extent of the lake. By calculating the area of the connected pixels for every month using the entire imagecollection. So far I know I have to use a function to go over every image, calculate the NDVI, mask all the pixels with a positive value and convert the raster to vector the calculate the area of the the neighbouring pixels with a negative value.

I’m having trouble putting all that into a working script, and would like to have some input on it.

// Create image collection of S-2 imagery
   var S2 = ee.ImageCollection('COPERNICUS/S2');
// Function to mask cloud from built-in quality band information on cloud
  var maskcloud1 = function(image) {
                   var QA60 = image.select(['QA60']);
  return image.updateMask(QA60.lt(1));
  };
// Function to calculate and add an NDVI band
  var addNDVI = function(image) {
  return image.addBands(image.normalizedDifference(['B8', 'B4']));
  };
// Function to mask cloud from built-in quality band information on cloud
  var maskcloud1 = function(image) {
                   var QA60 = image.select(['QA60']);
  return image.updateMask(QA60.lt(1));
};
// Function to mask all non-water bodies
  var collection =  ee.ImageCollection.fromImages(
              addNDVI.map(function(image) {
  return image.updateMask(image.lt(0));
  }));
// Convert the zones of the thresholded to vectors.
  var vectors = collection.reduceToVectors({
  geometry: roi,
  geometryType: 'polygon',
  eightConnected: false,
  labelProperty: 'zone',
  reducer: ee.Reducer.mean()
  });

Anyone who has some insights?

Edit: clarification on the code. Right now I get an error when performing the mask function. With the code I tried to include Al the different aspects that I need. However, I’m not sure of their linked correctly.

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