//ENVB 530 (Adv. GIS for Natural Resource Mgmt), McGill University Winter 2022
//Speed Learning Presentation (GEE Script)
//Syntax: Javascript
//Eidan Willis
var landsat8_sr = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR"); //Upload SR Imagery (note: collection is deprecated)
var srImage = ee.Image(landsat8_sr
.filterBounds(ee.Geometry.Point(-120.31077, 37.55858))
.filterDate('2013-09-15', '2013-09-27')
.sort('CLOUD_COVER')
.first());
Map.centerObject(ee.Geometry.Point(-120.31077, 37.55858), 11);
Map.addLayer(ee.Image(srImage.select('B5')), {}, 'Band 5 (NIR) Surface Reflectance');
var uiDisplayFlag = true
if (uiDisplayFlag) {
// Create User Interface portion --------------------------------------------------
// Create a panel to hold our widgets.
var panel = ui.Panel();
panel.style().set('width', '500px');
// Create an intro panel with labels.
var intro = ui.Panel([
ui.Label({
value: 'My User Interface',
style: {
fontSize: '20px',
fontWeight: 'bold'
}
}),
ui.Label('Click a point on the map to inspect.')
]);
panel.add(intro);
Map.style().set('cursor', 'crosshair');
// Name panels to hold lon/lat values of clicked point on map
var lon = ui.Label();
var lat = ui.Label();
// Display coords side-by-side
panel.add(ui.Panel([lon, lat], ui.Panel.Layout.flow('horizontal')));
//Register a callback to be executed when the map is clicked
Map.onClick(function(coords) {
// Update the lon/lat panel with values from the click event
lon.setValue('longitude: ' + coords.lon.toFixed(5)),
lat.setValue('latitude: ' + coords.lat.toFixed(5));
var point = ee.Geometry.Point(coords.lon, coords.lat);
var buffer = ee.FeatureCollection(point.buffer(1e4));
var distribution = ee.FeatureCollection.randomPoints(buffer);
var myHistogram = ui.Chart.image.histogram({
image: srImage.select('B5'), //Using NIR band from a Surface Reflectance image
region: distribution
});
myHistogram.setOptions({
title: 'Histogram of Near Infrared Surface Reflectance (B5)',
hAxis: {
title: 'NIR Value', //Specify horizontal axis title
//viewWindow: {min: 0, max: 750} <- Do this if you want to resize the x-axis
},
vAxis: {
title: 'Count' //Specify vertical axis title
},
legend: {
position: 'none' //Hide the legend
}
});
panel.widgets().set(2, myHistogram);
});
Map.style().set('cursor', 'crosshair');
// Add the panel to the ui.root.
ui.root.insert(0, panel);
}