Skip to content

Commit

Permalink
update to ghs urban layer
Browse files Browse the repository at this point in the history
  • Loading branch information
spatialthoughts committed Jul 8, 2023
1 parent ed532ef commit 3b0e15d
Show file tree
Hide file tree
Showing 34 changed files with 2,998 additions and 2,925 deletions.
7 changes: 4 additions & 3 deletions code/end_to_end_gee/01-Earth-Engine-Basics/06a_Import
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Let's import some data to Earth Engine

// Download the 'Urban Areas' from Natural Earth
// https://www.naturalearthdata.com/downloads/10m-cultural-vectors/
// We will upload the 'GHS Urban Centers' database from JRC
// https://ghsl.jrc.ec.europa.eu/ghs_stat_ucdb2015mt_r2019a.php

// Unzip and upload the ne_10m_urban_areas shapefile
// Download the shapefile from https://bit.ly/ghs-ucdb-shapefile
// Unzip and upload
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Let's import some data to Earth Engine
// Upload the ne_10m_urban_areas.shp shapefile

// Upload the 'GHS Urban Centers' database from JRC
// https://ghsl.jrc.ec.europa.eu/ghs_stat_ucdb2015mt_r2019a.php

// Download the shapefile from https://bit.ly/ghs-ucdb-shapefile
// Unzip and upload

// Import the collection
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

// Visualize the collection
Map.addLayer(urban, {color: 'blue'}, 'Urban Areas');
13 changes: 9 additions & 4 deletions code/end_to_end_gee/01-Earth-Engine-Basics/06c_Import_(exercise)
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Apply a filter to select only large urban areas
// Use the property 'area_sqkm' and select all features
// with area > 400 sq.km
// Apply a filter to select only large urban centers
// in your country and display it on the map.

var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
// Select all urban centers in your country with
// a population greater than 1000000

// Use the property 'CTR_MN_NM' containing country names
// Use the property 'P15' containing 2015 Population
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');
print(urban.first())
4 changes: 2 additions & 2 deletions code/end_to_end_gee/01-Earth-Engine-Basics/07a_Clipping
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**** Start of imports. If edited, may not auto-convert in the playground. ****/
var geometry = /* color: #d63000 */ee.Geometry.Point([77.5732612484775, 12.974168627832677]),
urban = ee.FeatureCollection("users/ujavalgandhi/e2e/ne_10m_urban_areas"),
s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED");
s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED"),
urban = ee.FeatureCollection("users/ujavalgandhi/e2e/ghs_urban_centers");
/***** End of imports. If edited, may not auto-convert in the playground. *****/
var rgbVis = {
min: 0.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection("users/ujavalgandhi/e2e/ne_10m_urban_areas");

// Find the feature id by adding the layer to the map and using Inspector.
var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');
// Find the name of the urban centre
// by adding the layer to the map and using Inspector.
var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));

var geometry = filtered.geometry();

Expand All @@ -19,5 +19,6 @@ var image = filtered.median();

var clipped = image.clip(geometry);

Map.centerObject(geometry);
Map.addLayer(clipped, rgbVis, 'Clipped');

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

// Change the filter to your home city or any urban area of your choice
var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
// Find the name of the urban centre
// by adding the layer to the map and using Inspector.
var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));

var geometry = filtered.geometry();

var rgbVis = {
Expand Down
5 changes: 3 additions & 2 deletions code/end_to_end_gee/01-Earth-Engine-Basics/08a_Export
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));

var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
var geometry = filtered.geometry();

var rgbVis = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));
var geometry = filtered.geometry();

var rgbVis = {
Expand All @@ -17,6 +17,7 @@ var image = filtered.median();

var clipped = image.clip(geometry);

Map.centerObject(geometry);
Map.addLayer(clipped, rgbVis, 'Clipped');

var exportImage = clipped.select('B.*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Write the export function to export the results

var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));
var geometry = filtered.geometry();

var rgbVis = {
Expand All @@ -19,6 +19,7 @@ var filtered = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
var image = filtered.median();

var clipped = image.clip(geometry);
Map.centerObject(geometry);
Map.addLayer(clipped, rgbVis, 'Clipped');

var exportImage = clipped.select('B.*');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED');
var urbanAreas = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urbanAreas = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

// Perform supervised classification for your city
// Find the feature id by adding the layer to the map and using Inspector.
var city = urbanAreas.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));

// Find the name of the urban centre
// by adding the layer to the map and using Inspector.
var city = urbanAreas.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));

var geometry = city.geometry();
Map.centerObject(geometry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var scaleImage = function(image) {
var filtered = s2
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
.filter(ee.Filter.bounds(geometry))
.filter(ee.Filter.date('2020-01-01', '2021-01-01'))
.map(maskS2clouds)
.map(scaleImage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var scaleImage = function(image) {
var filtered = s2
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
.filter(ee.Filter.bounds(geometry))
.filter(ee.Filter.date('2020-01-01', '2021-01-01'))
.map(maskS2clouds)
.map(scaleImage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var scaleImage = function(image) {
var filtered = s2
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
.filter(ee.Filter.bounds(geometry))
.filter(ee.Filter.date('2020-01-01', '2021-01-01'))
.map(maskS2clouds)
.map(scaleImage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ var nrgVis = {min: 0, max: 0.3, bands: ['B8', 'B4', 'B3']};
Map.addLayer(beforeComposite.clip(geometry), {min: 0, max: 0.3, bands: ['B4', 'B3', 'B2']}, 'Before')
Map.addLayer(afterComposite.clip(geometry), {min: 0, max: 0.4, bands: ['B4', 'B3', 'B2']}, 'After')

var ndviBefore = beforeComposite.normalizedDifference(['B8', 'B4']).rename(['ndvi']);
var ndviAfter = afterComposite.normalizedDifference(['B8', 'B4']).rename(['ndvi']);
var addIndices = function(image) {
var nbr = image.normalizedDifference(['B8', 'B12']).rename(['nbr']);
var ndvi = image.normalizedDifference(['B8', 'B4']).rename(['ndvi'])
return image.addBands(nbr).addBands(ndvi);
}

// You can try change detection with either NBR or NDVI
var selectedIndex = 'nbr';
var beforeNbr = addIndices(beforeComposite).select(selectedIndex);
var afterNbr = addIndices(afterComposite).select(selectedIndex);

// Loss of NDVI
var difference = ndviBefore.subtract(ndviAfter).clip(geometry)
// Change in Index
var difference = beforeNbr.subtract(afterNbr).clip(geometry)

var indexThreshold = 0.12;
var indexThreshold = 0.25;
var change = difference.gt(indexThreshold)

// Mask Waterbodies using WorldCover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Map.addLayer(composite2020, rgbVis, 'Composite 2020');


// Compute Spectral Distance between 2019 and 2020 images
var distance = composite2019.spectralDistance(composite2020);
var distance = composite2019.spectralDistance(composite2020, 'sam');
// GCPs were collected on 2020 image
// Find out which GCPs are still unchanged in 2021

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ var amplitude = harmonicTrendCoefficients.select('sin_1')
var rgb = ee.Image.cat([phase, amplitude, ee.Image(1)]).hsvToRgb();
Map.addLayer(rgb, {}, 'Phase (hue), Amplitude (sat)', false);


// The Phase and Amplitude values will be very different
// at farms following different cropping cycles
// Let's plot and compare the fitted time series
Expand Down
7 changes: 4 additions & 3 deletions docs/code/end_to_end_gee/01-Earth-Engine-Basics/06a_Import
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Let's import some data to Earth Engine

// Download the 'Urban Areas' from Natural Earth
// https://www.naturalearthdata.com/downloads/10m-cultural-vectors/
// We will upload the 'GHS Urban Centers' database from JRC
// https://ghsl.jrc.ec.europa.eu/ghs_stat_ucdb2015mt_r2019a.php

// Unzip and upload the ne_10m_urban_areas shapefile
// Download the shapefile from https://bit.ly/ghs-ucdb-shapefile
// Unzip and upload
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Let's import some data to Earth Engine
// Upload the ne_10m_urban_areas.shp shapefile

// Upload the 'GHS Urban Centers' database from JRC
// https://ghsl.jrc.ec.europa.eu/ghs_stat_ucdb2015mt_r2019a.php

// Download the shapefile from https://bit.ly/ghs-ucdb-shapefile
// Unzip and upload

// Import the collection
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

// Visualize the collection
Map.addLayer(urban, {color: 'blue'}, 'Urban Areas');
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Apply a filter to select only large urban areas
// Use the property 'area_sqkm' and select all features
// with area > 400 sq.km
// Apply a filter to select only large urban centers
// in your country and display it on the map.

var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
// Select all urban centers in your country with
// a population greater than 1000000

// Use the property 'CTR_MN_NM' containing country names
// Use the property 'P15' containing 2015 Population
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');
print(urban.first())
4 changes: 2 additions & 2 deletions docs/code/end_to_end_gee/01-Earth-Engine-Basics/07a_Clipping
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**** Start of imports. If edited, may not auto-convert in the playground. ****/
var geometry = /* color: #d63000 */ee.Geometry.Point([77.5732612484775, 12.974168627832677]),
urban = ee.FeatureCollection("users/ujavalgandhi/e2e/ne_10m_urban_areas"),
s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED");
s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED"),
urban = ee.FeatureCollection("users/ujavalgandhi/e2e/ghs_urban_centers");
/***** End of imports. If edited, may not auto-convert in the playground. *****/
var rgbVis = {
min: 0.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection("users/ujavalgandhi/e2e/ne_10m_urban_areas");

// Find the feature id by adding the layer to the map and using Inspector.
var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');
// Find the name of the urban centre
// by adding the layer to the map and using Inspector.
var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));

var geometry = filtered.geometry();

Expand All @@ -19,5 +19,6 @@ var image = filtered.median();

var clipped = image.clip(geometry);

Map.centerObject(geometry);
Map.addLayer(clipped, rgbVis, 'Clipped');

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

// Change the filter to your home city or any urban area of your choice
var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
// Find the name of the urban centre
// by adding the layer to the map and using Inspector.
var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));

var geometry = filtered.geometry();

var rgbVis = {
Expand Down
5 changes: 3 additions & 2 deletions docs/code/end_to_end_gee/01-Earth-Engine-Basics/08a_Export
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));

var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
var geometry = filtered.geometry();

var rgbVis = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));
var geometry = filtered.geometry();

var rgbVis = {
Expand All @@ -17,6 +17,7 @@ var image = filtered.median();

var clipped = image.clip(geometry);

Map.centerObject(geometry);
Map.addLayer(clipped, rgbVis, 'Clipped');

var exportImage = clipped.select('B.*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Write the export function to export the results

var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urban = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

var filtered = urban.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));
var filtered = urban.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));
var geometry = filtered.geometry();

var rgbVis = {
Expand All @@ -19,6 +19,7 @@ var filtered = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
var image = filtered.median();

var clipped = image.clip(geometry);
Map.centerObject(geometry);
Map.addLayer(clipped, rgbVis, 'Clipped');

var exportImage = clipped.select('B.*');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
var s2 = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED');
var urbanAreas = ee.FeatureCollection('users/ujavalgandhi/e2e/ne_10m_urban_areas');
var urbanAreas = ee.FeatureCollection('users/ujavalgandhi/e2e/ghs_urban_centers');

// Perform supervised classification for your city
// Find the feature id by adding the layer to the map and using Inspector.
var city = urbanAreas.filter(ee.Filter.eq('system:index', '00000000000000002bf8'));

// Find the name of the urban centre
// by adding the layer to the map and using Inspector.
var city = urbanAreas.filter(ee.Filter.eq('UC_NM_MN', 'Bengaluru'));

var geometry = city.geometry();
Map.centerObject(geometry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var scaleImage = function(image) {
var filtered = s2
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
.filter(ee.Filter.bounds(geometry))
.filter(ee.Filter.date('2020-01-01', '2021-01-01'))
.map(maskS2clouds)
.map(scaleImage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var scaleImage = function(image) {
var filtered = s2
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
.filter(ee.Filter.bounds(geometry))
.filter(ee.Filter.date('2020-01-01', '2021-01-01'))
.map(maskS2clouds)
.map(scaleImage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var scaleImage = function(image) {
var filtered = s2
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
.filter(ee.Filter.bounds(geometry))
.filter(ee.Filter.date('2020-01-01', '2021-01-01'))
.map(maskS2clouds)
.map(scaleImage);

Expand Down
Loading

0 comments on commit 3b0e15d

Please sign in to comment.