TransWikia.com

Estimating Water Area for Several Regions in GEE

Geographic Information Systems Asked on January 10, 2021

I have been trying to estimate the water area for several regions using the JRC/GSW1_2/MonthlyHistory. Here is a sample of the code:

//Opening the JRC Water Data
var water_data = ee.ImageCollection("JRC/GSW1_2/MonthlyHistory")
var filtered = water_data.filter(
  ee.Filter.date('2018-01-01', '2018-01-31'))
var water_area = ee.Image(filtered.first())

//Creating Region Variable
var turkeyProvinces = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level1")
    .filter(ee.Filter.eq("ADM0_NAME", "Turkey"));

//Calculating Water Areas
var calculateClassArea = function(feature) {
    var areas = ee.Image.pixelArea().addBands(water_area)
    .reduceRegion({
      reducer: ee.Reducer.sum().group({
      groupField: 1,
      groupName: 'class',
    }),
    geometry: feature.geometry(),
    scale: 30,
    maxPixels: 1e10
    })
return areas 
}
var districtAreas = turkeyProvinces.map(calculateClassArea);

The problem is that the code estimates the area of the regions instead of the Water areas within the regions. Link to the code.

One Answer

Make sure you read and understand the data description. Also, add the image to the map to understand what is happening. You would have seen that there is no data for Turkey for the image you have requested:

//Opening the JRC Water Data
var water_data = ee.ImageCollection("JRC/GSW1_2/MonthlyHistory")
var filtered = water_data.filter(
  ee.Filter.date('2018-01-01', '2018-01-31'))
var water_area = ee.Image(filtered.first())

// print and display map
print(water_area)
// 0 = no data (black), 1 = Not water (yellow), 2 = Water (blue)
Map.addLayer(water_area, {palette: ["101010","dcff19","280eff"],max: 2}, 'water map')

To estimate only the area of water, change line 13:

var areas = water_area.eq(2).selfMask().multiply(ee.Image.pixelArea())

Then reduceRegion() will only calculate the area of the pixels representing water, if they are present within your geometry argument.

Note that in your current export, properties 0 represents the area of no data, 1 of 'not water' and 2 the area of water. So it is not 'wrong' that property returns the area of the feature (thus of no data). By changing line 13, you will only export the water area and you do not need the grouped reducer. Sample of that code.

Correct answer by Kuik on January 10, 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