-
Notifications
You must be signed in to change notification settings - Fork 0
/
Javascript
181 lines (118 loc) · 4.66 KB
/
Javascript
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Map zooms to the point of interest.
Map.centerObject(geometry3,15);
// Getting palettes for later and change basemap from Google basemaps.
var palettes = require('users/gena/packages:palettes');
var JMpalette = palettes.colorbrewer.GnBu[7];
var baseChange = [{featureType: 'all', stylers: [{visibility: 'off'}]}];
//Set map option in the display.
Map.setOptions('baseChange', {'baseChange': baseChange});
// Import Jamaica JAD69 shapefile.
var jam = ee.FeatureCollection(jamshp).geometry();
// Add to display.
Map.addLayer(jam, {color:'#666699'}, "JAM")
///////////////////// Requesting Data //////////////////////////
//Create cloud mask function.
function maskS2clouds(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
}
// Request Sentinel-2 data with specific parameters.
var start = ee.Date('2021-01-01');
var finish = ee.Date('2021-01-20');
var collection = ee.ImageCollection('COPERNICUS/S2')
.filterDate(start,finish)
.filterBounds(geometry) // Uses boundary of shapefile.
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10)) //Filters out images with cloud cover >10%.
.map(maskS2clouds) // Add cloud mask for existing clouds.
.limit(1); // Select only the first image in the collection.
var rgbVis = {bands: ['B8','B4', 'B3']}; // Select image bands from Sentinel-2
// Add function to select and display image in the console and display.
function addImage(imageL) { // Display each image in collection.
var id = imageL.id;
var image = ee.Image(imageL.id);
Map.addLayer(collection.mean(),rgbVis,id)
}
collection.evaluate(function(collection) { // Use map on client-side.
print(collection.features);
collection.features.map(addImage);
})
// Get SRTM data
var dataset = ee.Image('USGS/SRTMGL1_003');
var elevation = dataset.select('elevation');
var slope = ee.Terrain.slope(elevation).clip(geometry2);
Map.addLayer(slope, {min: 0, max: 60}, 'slope');
//Create a chart.
var chart = ui.Chart.image.byRegion({
image: elevation,
regions: geometry3,
scale: 10
});
// Display the chart in the console.
print(chart);
// Get MERIT data to compare with SRTM 2000 data.
var dataset1 = ee.Image('MERIT/DEM/v1_0_3').clip(geometry2);
var visualization = {
bands: ['dem']
};
// Map.addLayer(dataset1, visualization, 'Elevation');
//Create a chart.
var chart0 = ui.Chart.image.byRegion({
image: dataset,
regions: geometry2,
scale: 10
});
// Display the chart in the console.
print(chart0);
// Elevation statistics from SRTM data
var img = ee.Image('USGS/SRTMGL1_003').select('elevation');
var meanElev = img.sample({region: geometry, scale: 25000, numPixels: 100, geometries: true}); //250
print ('Mean elev info:', meanElev)
// Combine the mean and standard deviation reducers.
var reducers = ee.Reducer.mean().combine({
reducer2: ee.Reducer.stdDev(),
sharedInputs: true
});
// Use the combined reducer to get the mean and SD of the image.
var stats = img.reduceRegion({
reducer: reducers,
geometry: geometry2,
bestEffort: true,
});
// Display the dictionary of band means and SDs.
print("statistics", stats);
/////////////////////// Windalco pit dimensions///////////////////////////////////
//Get area of Windalco red mud pit ROI (region of interest).
var windalcoarea = geometry2.area({'maxError': 1});
print ('Pit area:', windalcoarea)
// This function computes the feature's geometry area and adds it as a property.
var segLength = function(feature) {
return feature.set({segLength: feature.geometry().length()});
};
// Map the area getting function over the FeatureCollection.
var lengthAdded = geometry4.map(segLength);
// Print the first feature from the collection with the added property.
print('transect lengths:', lengthAdded);
var transectLengths = lengthAdded.aggregate_array("segLength")
print(transectLengths)
//Get statistics for transect
var sum = transectLengths.reduce(ee.Reducer.sum())
print ('Total transect length:',sum)
var mean = transectLengths.reduce(ee.Reducer.mean())
print ('Mean transect length:',mean)
var stdDev = transectLengths.reduce(ee.Reducer.stdDev())
print ('StdDev transect length:',stdDev)
////////////// Export any image to the Drive ////////////
Export.image.toDrive({
image: img,
description: 'pit_elevation',
scale: 10,
region: geometry2,
crs: 'EPSG:24200', //EPSG:3448 for JAD2001
maxPixels: 1e10
});