-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced_maputo_image_computations.js
142 lines (109 loc) · 3.52 KB
/
advanced_maputo_image_computations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//// COMPUTATIONS WITH IMAGES ////
var srtm = ee.Image("CGIAR/SRTM90_V4"),
maputo = /* color: #d63000 */ee.Geometry.Polygon(
[[[32.41235534020745, -25.796423346876526],
[32.347839812434195, -25.953277491083657],
[32.537274801862594, -26.05568172245262],
[32.81597296405779, -25.957016557703238],
[32.83032182380885, -25.776014694146827],
[32.60592314710322, -25.725985956971844]]]),
dem1 = ee.Image("users/sitoeimildo/montes1");
// Load SRTM Digital Elevation Data Version 4 from search bar.
// Rename it to srtm.
// Calculate terrain products and print the result.
var terrain = ee.Terrain.products(srtm);
print(terrain);
// Select the hillshade band and display it.
var hs = terrain.select('hillshade');
// Display it.
var vp = {
bands: 'hillshade',
min: 60,
max: 230,
palette : ['green', 'yellow', 'grey']
};
Map.addLayer(hs, vp, 'hillshade');
/// Calculate mean elevation in a region.
// Create geometry using GUI tool and call it polygon.
// Print the geometry.
print(maputo);
// Calculate mean elevation inside geometry.
var meanElev = srtm.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: maputo
});
print('Mean elevation in Maputo', meanElev);
/////////////////////////////////////////////////////////////////////////
// Exercise: apply the reduceRegions function with a FeatureCollection //
/////////////////////////////////////////////////////////////////////////
// Create 3 polygons in a new layer
print(polygons);
// Calculate the mean elevation for the three polygons using reduceRegions
var meanElev = srtm.reduceRegions({
collection: polygons,
reducer: ee.Reducer.mean()
});
// Print the results
print('Mean elevation', meanElev);
// Export results as table
Export.table.toDrive({
collection: meanElev,
description: 'mean_elevation',
folder: 'wfp_mozambique_training',
selectors: 'mean',
fileFormat: 'SHP'
});
// Calculate and apply a mask
// Load the ASTER GDEM (montes1, montes2) from your assets.
var dem2 = ee.Image('users/sitoeimildo/montes2');
print(dem2);
// Put the tiles in an image collection.
var col = ee.ImageCollection([dem1, dem2]);
print(col);
// Mosaic the tiles into a single image.
var mosaic = col.mosaic();
print(mosaic);
var vp = {
bands: 'b1',
min: 20,
max: 800,
palette: ['green', 'yellow', 'orange', 'brown']
}
Map.addLayer(mosaic, vp);
// Get all pixels greater than 300 meters: this will create a binary image.
var mask = mosaic.gt(300)
Map.addLayer(mask);
// Mask (set to no data) all areas below 300 meters elevation.
var mosaicMasked = mosaic.updateMask(mask);
Map.addLayer(mosaicMasked, vp, 'masked');
Export.image.toDrive({
image: mosaicMasked,
description: 'masked_dem',
folder: 'wfp_mozambique_training',
scale: 250,
region: geometry
});
//////////////////////////////////////////////////////////
/// Exercise: mask areas below 1000 m from srtm ///
//////////////////////////////////////////////////////////
// Extract areas above 1000 m.
var mask2 = srtm.gt(1000)
Map.addLayer(mask2);
// Mask (set to no data) all areas below 1000 meters elevation.
var srtm1000 = srtm.updateMask(mask2);
// Visualize the masked layer
var vp1000 = {
bands: 'elevation',
min: 1000,
max: 6000,
palette: ['black', 'purple', 'yellow']
}
Map.addLayer(srtm1000, vp1000, 'srtm1000');
// Export results in image format
Export.image.toDrive({
image: srtm1000,
description: 'srtm_1000',
folder: 'wfp_mozambique_training',
scale: 100,
region: geometry2
});