I'm trying to extract different indices vales at random points in Google Earth Engine. I have calculated NDVI, NDBI, NDSI for the area from the Landsat 5 image. Then created a mosaic of these three indices. After that trying to reduceRegions()
to extract the values from the mosaiced image at random points.
//---------------------------------------------------------------------------
//------------- --------------INDICES CALCULATION----------------------------
//---------------------------------------------------------------------------
// import the boundary layer of Mumbai
var mumbai = ee.FeatureCollection('users/badalmohanty/GreaterBombay');
Map.centerObject(mumbai, 10);
//------------- import Landsat 5 dataset 9th March 1990----------------------
var dataset = ee.ImageCollection('LANDSAT/LT05/C02/T1_L2')
.filter(ee.Filter.eq('WRS_PATH', 148))
.filter(ee.Filter.eq('WRS_ROW', 47))
.filterDate('1990-03-01', '1990-04-01');
// Applies scaling factors.
function applyScaleFactors(image) {
var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
var thermalBand = image.select('ST_B6').multiply(0.00341802).add(149.0);
return image.addBands(opticalBands, null, true)
.addBands(thermalBand, null, true);
}
dataset = dataset.map(applyScaleFactors);
// take least clouded image
var image = ee.Image(dataset.sort('CLOUD_COVER').first().clip(mumbai));
// calculate NDVI
var ndvi = image.normalizedDifference(['SR_B4', 'SR_B3']);
// calculate NDBI
var ndbi = image.normalizedDifference(['SR_B5', 'SR_B4']);
// calculate NDSI
var ndsi = image.normalizedDifference(['SR_B7', 'SR_B2']);
var mosaic = ee.ImageCollection([
ndbi.visualize({palette: 'blue'}),
ndvi.visualize({palette: 'green'}),
ndsi.visualize({palette: 'red'})
]).mosaic();
Map.addLayer(mosaic, {}, 'custom mosaic');
//---------------------------------------------------------------------------
//------------- ----------EXTRACTION AT RANDOM POINTS------------------------
//---------------------------------------------------------------------------
// load the random points
var randomPoints = ee.FeatureCollection('users/badalmohanty/GreaterMumbaiRandomPoints');
// reduce the region
var poinData = mosaic.reduceRegions({
collection: randomPoints,
reducer: ee.Reducer.first()
});
// print it.
print(poinData);
// export it.
Export.table.toDrive(poinData, "test1");
There are several problems in this which I am not able to solve.
- The
data type
of all the bands of themosaic
image isuint8
andCRS
isEPSG:4326
. Where as individual indices images (NDVI, NDBI, NDSI) havedata type
offloat ∈ [-1, 1]
andCRS
areEPSG:32643
. - the code shows the following error,
FeatureCollection (Error) Image.reduceRegions: The default WGS84 projection is invalid for aggregations. Specify a scale or crs & crs_transform.
Why these issues are coming and how to solve them?
My aim here is to extract the indices data at those random points. instead of doing that for individual indices one by one, I tried to make a composite and extract all values at once. If my method is very wrong, can anyone suggest how I can achieve this result?
I have attached the asset link to the used feature collections. Also the drive link.
- GreaterBombay feature collection (Drive link).
- GreaterMumbaiRandomPoints feature collection (Drive link).