Tutorials/Post - Remote Sensing, GIS, Earth System, Geo-AI/ML

JRC Historical Flood Visualization and Download with Google Earth Engine

This is prepared with regard to the Google Earth Engine training in Vietnam.
The goal is to visualize the Joint Research Centre (JRC) Flood Occurrence Dataset and download the processed image. We will be using JRC Monthly Water History v1.0 (1984-2015). The highlight of this dataset is

Band NameLabel
water0 = no data
1 = not water
2 = water

To learn more about the dataset, please see this Nature, 2016 paper.

  1. Let’s start by defining the useful image collection and feature collection. I have tried to keep the variable names as explanatory as possible.
    var jrcDataset = ee.ImageCollection('JRC/GSW1_0/MonthlyHistory');
    var countriesLayer = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw');
    
  2. Then we will define some variables for the output, like datetime, area, palette etc. Note we can define geometry in three ways:-
    1. You can have list of coordinates and generate Polygon using ee.Geometry.Polygon function.
    2. You can directly draw polygon using the draw tool.
    3. If you are focusing on country, you can filter from the countriesLayer
    var coordinates = [99.63, 14.37, 100.09, 14.77, 100.38, 14.33, 99.83, 14.05];
    var geometry = ee.Geometry.Polygon(coordinates);
    // or this can come directly as drawing polygon
    // or if you wanna focus on country, then
    var _country = ['Vietnam'];
    // filter the countriesLayer to include only the _country
    var geometry = countriesLayer.filter(ee.Filter.inList('Country', _country)).geometry();
    // Define start and end date
    var startDate = '2000-01-01';
    var endDate = '2004-01-01';
    // Define palette
    var palette = ['c10000,d742f4,001556,b7d2f7'];
    
  3. Now filter the dataset to contain the required area and date.
    var filteredJRCDataset = jrcDataset.filterBounds(geometry).filterDate(startDate, endDate);
    
  4. Since 0 is no data as explained before, we will focus on the valid data only. Set the properties for the valid image collection.
    var validFilteredJRCDataset = filteredJRCDataset.map(function (img) {
      var valid = img.gt(0);
      return valid.set('system:time_start', img.get('system:time_start'));
    });
    
  5. Now get the image collection containing water data which is 2, and set the properties as before.
    var waterJRCDataset = filteredJRCDataset.map(function (img) {
      var waterImage = img.select('water').eq(2);
      return waterImage.set('system:time_start', img.get('system:time_start'));
    });
    
  6. Let’s calculate the total water percentage image for the valid dataset for the given variables. The percentage is calculated as totalWater/totalValidData * 100
    var totalValidJRCDataset = validFilteredJRCDataset.sum().toFloat();
    var totalWaterJRCDataset = waterJRCDataset.sum().toFloat();
    var totalWaterPercentJRCDataset = totalWaterJRCDataset.divide(totalValidJRCDataset).multiply(100);
    
  7. Since the totalWaterPercentJRCDataset also contains data from the totalValidJRCDataset, as we filtered image greater than 0, let’s use that as the mask on the totalWaterPercentJRCDataset and update it.
    var maskedWaterImage = totalWaterPercentJRCDataset.gt(1);
    var waterPercentImage = totalWaterPercentJRCDataset.updateMask(maskedWaterImage);
    
  8. Filter to the geometry and add it to the map with the given palette
    waterPercentImage = waterPercentImage.clip(geometry);
    Map.centerObject(geometry);
    Map.addLayer(waterPercentImage, {'min': '0', 'max': '100', 'bands': 'water', 'palette': palette}, 'filtered');
    
  9. Now let’s get the download URL using the getDownloadURL function
    var link = waterPercentImage.getDownloadURL({
      'name': 'water_extract',
      'scale': 30
    });
    print(link);
    

    Be careful with the large area. The maximum download is 1024 MB. You might need to adjust your scale for large area download.

If I had to do this on a server, it would take months to do the processing. A slight change in the parameter would require same time. But because of Earth Engine, this is possible within minutes to process the historical archive. Sincere gratitude to Google for providing the cloud processing.

Previous

Updating Column Name and Column Value in QGIS

Next

Digital Technologies For Resilience Workshop

7 Comments

  1. I real pleased to find this internet site on bing, just what I was looking for :
    D also saved to fav.

  2. I have been examinating out a few of your stories and it’s pretty good stuff.
    I will definitely bookmark your blog.

  3. Shashwat 13

    Absolutely thrilled to discover this. Keep up the good work solti!

  4. Dom

    Hello,

    I want to get the full global map for 1 month.

    What I am doing now is: (1) split the global map into thousands of small pieces, then (2) getDownloadURL for each piece and (3) use wget to download file from that URL. (I run GEE in python API).

    It takes too many time (more than 3 days in total). The time to download is short, but the time for sending HTTP request and waiting for the response is quite long.

    So, do you have any idea to get the full global map for fast, without sending too much HTTP request? or let’s say, without splitting the global map into too many tiny pieces?

    • biplovbhandari

      I would use Earth Engine code editor (web version) and use export to google drive. I have successfully used google drive (or assets) to export very large area (multiple countries, not the world of-course!). That way I have access to the raster files.
      If you are adamant in using Python API, you can use the Google Drive API to connect them.
      Just keep in mind that the getDownloadURL are not meant for downloading very large area, export is the preferred way.

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by WordPress & Theme by Anders Norén