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 Name | Label |
---|---|
water | 0 = no data 1 = not water 2 = water |
To learn more about the dataset, please see this Nature, 2016 paper.
- 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');
- Then we will define some variables for the output, like datetime, area, palette etc. Note we can define geometry in three ways:-
- You can have list of coordinates and generate Polygon using
ee.Geometry.Polygon
function. - You can directly draw polygon using the draw tool.
- 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'];
- You can have list of coordinates and generate Polygon using
- Now filter the dataset to contain the required area and date.
var filteredJRCDataset = jrcDataset.filterBounds(geometry).filterDate(startDate, endDate);
- 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')); });
- 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')); });
- 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);
- 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);
- 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');
- Now let’s get the download URL using the
getDownloadURL
functionvar 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.
pitstopexclusive.com
I real pleased to find this internet site on bing, just what I was looking for :
D also saved to fav.
Biplov Bhandari
Glad to know that you find it helpful! Thanks for taking time to read. Cheers!
removing vomit stain from carpet
I have been examinating out a few of your stories and it’s pretty good stuff.
I will definitely bookmark your blog.
Biplov Bhandari
Thanks for taking time to read. Cheers!
Shashwat 13
Absolutely thrilled to discover this. Keep up the good work solti!
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.