Geographic Information Systems Asked on January 17, 2021
Having read the Google Earth Engine guide ‘NDVI, Mapping a Function over a Collection, Quality Mosaicking’ (https://developers.google.com/earth-engine/tutorials/tutorial_api_06) I am trying to compute a Normalized Difference Vegetation Index (NDVI) image from a LANDSAT/LC08/C01/T1_TOA image and have written the following code:
var roi = ee.Geometry.Rectangle(138.78575924068758, 35.99620792950091, 140.41997554928133, 35.27856379077837);
Map.centerObject(roi, 8);
Map.addLayer(roi, {}, 'roi');
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
var image = ee.Image(
l8.filterBounds(roi)
.filterDate('2015-01-01', '2015-12-31')
.sort('CLOUD_COVER')
.first()
);
print(image)
var nir = image.select('B5');
var red = image.select('B4');
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');
print(ndvi)
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
print(ndviParams)
Map.addLayer(ndvi, ndviParams, 'NDVI image')
Also here is the link to the code: https://code.earthengine.google.com/b46f6ec756fe35c65d302eedbb23d5da.
In the console all of the code appears to compute correctly but for some reason the map layer is not added within the region of interest (roi) and I have no idea why. Also I have tried to use the clip tool (this code: https://code.earthengine.google.com/3c93d1c804aa21ff0c0fb082caa953f3) but the map layer is not added at all.
How can I adjust my code so that the NDVI map layer is added within the region of interest (roi)?
The reason for this is because the function ee.Image()
is designed to open a single image and your region of interest spans a couple frames of Landsat 8 imagery.
To see this, you can try to define a point at (139.64, 35.65) and for your l8.filterBounds()
function use this point instead of roi
. Now you should see that another landsat image is used for analysis.
If this image doesn't cover enough of your region, than create other images similar to your image
variable to analyse different parts of the roi
.
Answered by AdoMath on January 17, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP