Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
spatialthoughts committed Aug 18, 2023
1 parent 0207e14 commit b9a09cb
Show file tree
Hide file tree
Showing 47 changed files with 2,057 additions and 1,810 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ var withNdvi = filtered.map(addNDVI);

var composite = withNdvi.median();

var ndviComposite = composite.select('ndvi').clip(geometry);
var ndviComposite = composite.select('ndvi');

var palette = [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
'74A901', '66A000', '529400', '3E8601', '207401', '056201',
'004C00', '023B01', '012E01', '011D01', '011301'];

var ndviVis = {min:0, max:0.5, palette: palette };
Map.addLayer(ndviComposite, ndviVis, 'ndvi');
Map.addLayer(ndviComposite.clip(geometry), ndviVis, 'ndvi');
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ function addIndices(image) {
var withIndices = filtered.map(addIndices);

// Composite
var composite = withIndices.median().clip(geometry);
var composite = withIndices.median();
print(composite);

// Extract the 'ndwi' band and display a NDWI map
// Extract the 'ndwi' band
// Clip and display a NDWI map
// use the palette ['white', 'blue']
// Hint: Use .select() function to select a band

Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ var filtered = s2
.filter(ee.Filter.bounds(geometry))
.select('B.*');

var composite = filtered.median().clip(geometry) ;
var composite = filtered.median();

// Display the input composite.
Map.addLayer(composite, rgbVis, 'image');
Map.addLayer(composite.clip(geometry), rgbVis, 'image');

var gcps = urban.merge(bare).merge(water).merge(vegetation);

Expand All @@ -258,6 +258,6 @@ Map.centerObject(geometry);
// Urban, Bare, Water, Vegetation
var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];

Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');


Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ var filtered = s2
.filter(ee.Filter.bounds(geometry))
.select('B.*');

var composite = filtered.median().clip(geometry);
var composite = filtered.median();

// Display the input composite.

var rgbVis = {min: 0.0, max: 3000, bands: ['B4', 'B3', 'B2']};
Map.addLayer(composite, rgbVis, 'image');
Map.addLayer(composite.clip(geometry), rgbVis, 'image');

// Exercise
// Add training points for 4 classes
Expand Down Expand Up @@ -60,6 +60,6 @@ Map.addLayer(composite, rgbVis, 'image');
// // Urban, Bare, Water, Vegetation
// var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];

// Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
// Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');


Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ var filtered = s2
.filter(ee.Filter.bounds(geometry))
.select('B.*');

var composite = filtered.median().clip(geometry);
var composite = filtered.median();

// Display the input composite.
var rgbVis = {
min: 0.0,
max: 3000,
bands: ['B4', 'B3', 'B2'],
};
Map.addLayer(composite, rgbVis, 'image');
Map.addLayer(composite.clip(geometry), rgbVis, 'image');

var gcps = urban.merge(bare).merge(water).merge(vegetation);

Expand All @@ -48,7 +48,7 @@ var classified = composite.classify(classifier);
// Urban, Bare, Water, Vegetation
var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];

Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');
// Display the GCPs
// We use the style() function to style the GCPs
var palette = ee.List(palette);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ var filtered = s2
.filter(ee.Filter.bounds(geometry))
.select('B.*');

var composite = filtered.median().clip(geometry);
var composite = filtered.median();

// Display the input composite.
Map.addLayer(composite, rgbVis, 'image');
Map.addLayer(composite.clip(geometry), rgbVis, 'image');


// Overlay the point on the image to get training data.
Expand All @@ -44,4 +44,4 @@ var classifier = ee.Classifier.smileRandomForest(50)
var classified = composite.classify(classifier);

var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];
Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ var filtered = s2
.filter(ee.Filter.bounds(geometry))
.select('B.*');

var composite = filtered.median().clip(geometry);
var composite = filtered.median();

// Display the input composite.
Map.addLayer(composite, rgbVis, 'image');
Map.addLayer(composite.clip(geometry), rgbVis, 'image');


// Add a random column and split the GCPs into training and validation set
Expand Down Expand Up @@ -53,7 +53,7 @@ var classifier = ee.Classifier.smileRandomForest(50)
var classified = composite.classify(classifier);

var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];
Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');
//**************************************************************************
// Accuracy Assessment
//**************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ var filtered = s2
.filter(ee.Filter.bounds(geometry))
.select('B.*');

var composite = filtered.median().clip(geometry)
var composite = filtered.median();

// Display the input composite.
Map.addLayer(composite, rgbVis, 'image');
Map.addLayer(composite.clip(geometry), rgbVis, 'image');


// Add a random column and split the GCPs into training and validation set
Expand Down Expand Up @@ -55,7 +55,7 @@ var classifier = ee.Classifier.smileRandomForest(50)
var classified = composite.classify(classifier);

var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];
Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');

//**************************************************************************
// Accuracy Assessment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var filtered = s2
.map(maskCloudAndShadowsSR)
.select('B.*');

var composite = filtered.median().clip(geometry);
var composite = filtered.median();


var addIndices = function(image) {
Expand All @@ -62,7 +62,7 @@ var slope = ee.Terrain.slope(alos.select('AVE_DSM')).rename('slope');
var composite = composite.addBands(elev).addBands(slope);

var visParams = {bands: ['B4', 'B3', 'B2'], min: 0, max: 3000, gamma: 1.2};
Map.addLayer(composite, visParams, 'RGB');
Map.addLayer(composite.clip(geometry), visParams, 'RGB');

// Normalize the image

Expand Down Expand Up @@ -130,7 +130,7 @@ var classifier = ee.Classifier.smileRandomForest(50)
var classified = composite.classify(classifier);

var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];
Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');

//**************************************************************************
// Accuracy Assessment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var filtered = s2
.map(maskCloudAndShadowsSR)
.select('B.*');

var composite = filtered.median().clip(geometry) ;
var composite = filtered.median();

var addIndices = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename(['ndvi']);
Expand All @@ -60,7 +60,7 @@ var slope = ee.Terrain.slope(alos.select('AVE_DSM')).rename('slope');
var composite = composite.addBands(elev).addBands(slope);

var visParams = {bands: ['B4', 'B3', 'B2'], min: 0, max: 3000, gamma: 1.2};
Map.addLayer(composite, visParams, 'RGB');
Map.addLayer(composite.clip(geometry), visParams, 'RGB');

// Normalize the image

Expand Down Expand Up @@ -129,7 +129,7 @@ var classifier = ee.Classifier.smileRandomForest(50)
var classified = composite.classify(classifier);

var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];
Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');
//**************************************************************************
// Accuracy Assessment
//**************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var filtered = s2
.map(maskCloudAndShadowsSR)
.select('B.*');

var composite = filtered.median().clip(geometry) ;
var composite = filtered.median();

var addIndices = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename(['ndvi']);
Expand All @@ -60,7 +60,7 @@ var slope = ee.Terrain.slope(alos.select('AVE_DSM')).rename('slope');
var composite = composite.addBands(elev).addBands(slope);

var visParams = {bands: ['B4', 'B3', 'B2'], min: 0, max: 3000, gamma: 1.2};
Map.addLayer(composite, visParams, 'RGB');
Map.addLayer(composite.clip(geometry), visParams, 'RGB');

// Normalize the image

Expand Down Expand Up @@ -129,7 +129,7 @@ var classifier = ee.Classifier.smileRandomForest(50)
var classified = composite.classify(classifier);

var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];
Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');

//**************************************************************************
// Accuracy Assessment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var filtered = s2
.map(maskCloudAndShadowsSR)
.select('B.*');

var composite = filtered.median().clip(geometry) ;
var composite = filtered.median();

var addIndices = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename(['ndvi']);
Expand All @@ -60,7 +60,7 @@ var slope = ee.Terrain.slope(alos.select('AVE_DSM')).rename('slope');
var composite = composite.addBands(elev).addBands(slope);

var visParams = {bands: ['B4', 'B3', 'B2'], min: 0, max: 3000, gamma: 1.2};
Map.addLayer(composite, visParams, 'RGB');
Map.addLayer(composite.clip(geometry), visParams, 'RGB');

// Normalize the image

Expand Down Expand Up @@ -129,7 +129,7 @@ var classifier = ee.Classifier.smileRandomForest(50)
var classified = composite.classify(classifier);

var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];
Map.addLayer(classified, {min: 0, max: 3, palette: palette}, '2019');
Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '2019');
// Exercise

// Use the Export.image.toAsset() function to export the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ var filtered = s2
.map(maskS2clouds);


var image2019 = filtered.median().clip(geometry);
var image2019 = filtered.median();
// Display the input composite.
Map.addLayer(image2019, rgbVis, '2019');
Map.addLayer(image2019.clip(geometry), rgbVis, '2019');

var filtered = s2
.filter(ee.Filter.date('2020-01-01', '2020-02-01'))
.filter(ee.Filter.bounds(bangalore))
.map(maskS2clouds)

var image2020 = filtered.median().clip(geometry);
var image2020 = filtered.median();

Map.addLayer(image2020, rgbVis, '2020');
Map.addLayer(image2020.clip(geometry), rgbVis, '2020');
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ var filtered = s2
.map(maskS2clouds);


var image2019 = filtered.median().clip(geometry);
var image2019 = filtered.median();
// Display the input composite.
Map.addLayer(image2019, rgbVis, '2019');
Map.addLayer(image2019.clip(geometry), rgbVis, '2019');

var filtered = s2
.filter(ee.Filter.date('2020-01-01', '2020-02-01'))
.filter(ee.Filter.bounds(bangalore))
.map(maskS2clouds);

var image2020 = filtered.median().clip(geometry);
var image2020 = filtered.median();

Map.addLayer(image2020, rgbVis, '2020');
Map.addLayer(image2020.clip(geometry), rgbVis, '2020');

var stackedImage = image2019.addBands(image2020);

Expand All @@ -60,4 +60,4 @@ var classifier = ee.Classifier.smileRandomForest(50).train({

// Classify the image.
var classified = stackedImage.classify(classifier);
Map.addLayer(classified, {min: 0, max: 1, palette: ['white', 'red']}, 'change');
Map.addLayer(classified.clip(geometry), {min: 0, max: 1, palette: ['white', 'red']}, 'change');
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ var filtered = s2
.map(maskS2clouds);


var image2019 = filtered.median().clip(geometry);
var image2019 = filtered.median();
// Display the input composite.
Map.addLayer(image2019, rgbVis, '2019');
Map.addLayer(image2019.clip(geometry), rgbVis, '2019');

var filtered = s2
.filter(ee.Filter.date('2020-01-01', '2020-02-01'))
.filter(ee.Filter.bounds(bangalore))
.map(maskS2clouds);

var image2020 = filtered.median().clip(geometry);
var image2020 = filtered.median();

Map.addLayer(image2020, rgbVis, '2020');
Map.addLayer(image2020.clip(geometry), rgbVis, '2020');

// Exercise

Expand Down Expand Up @@ -74,4 +74,4 @@ var classifier = ee.Classifier.smileRandomForest(50).train({

// Classify the image.
var classified = stackedImage.classify(classifier);
Map.addLayer(classified, {min: 0, max: 1, palette: ['white', 'red']}, 'change');
Map.addLayer(classified.clip(geometry), {min: 0, max: 1, palette: ['white', 'red']}, 'change');
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,9 @@ var filtered = s2
.filter(ee.Filter.bounds(geometry))
.select('B.*');


var before = filtered.median().clip(geometry);
var before = filtered.median();
// Display the input composite.
Map.addLayer(before, rgbVis, 'before');
Map.addLayer(before.clip(geometry), rgbVis, 'before');

var training = urban.merge(bare).merge(water).merge(vegetation);

Expand All @@ -274,21 +273,20 @@ var classifier = ee.Classifier.smileRandomForest(50).train({
var beforeClassified = before.classify(classifier);
var palette = ['#cc6d8f', '#ffc107', '#1e88e5', '#004d40' ];
var classifiedVis = {min: 0, max: 3, palette: palette};
Map.addLayer(beforeClassified, classifiedVis, 'before_classified');
Map.addLayer(beforeClassified.clip(geometry), classifiedVis, 'before_classified');


// 2020 Jan
var after = s2
.filter(ee.Filter.date('2020-01-01', '2020-02-01'))
.filter(ee.Filter.bounds(geometry))
.select('B.*')
.median()
.clip(geometry);

.median();

Map.addLayer(after, rgbVis, 'after');

// Classify the image.
var afterClassified= after.classify(classifier);
Map.addLayer(afterClassified, classifiedVis, 'after_classified');
Map.addLayer(afterClassified.clip(geometry), classifiedVis, 'after_classified');


Loading

0 comments on commit b9a09cb

Please sign in to comment.