CÓDIGO DE TEXTURAS NO GEE #10
elianebenaion
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Pessoal estou tentando criar um código para identificar texturas no GEE, mas ele tá aparecendo sempre esse erro: SyntaxError: Unexpected token (73:1)
código: // Import the Shapefile
var shapefile = ee.FeatureCollection("projects/ee-geoprocessamentojp/assets/tester");
var area = shapefile.geometry().bounds().centroid();
// Load Landsat 8 Images
var images = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
.filterDate('2022-01-01', '2023-12-31')
.filterBounds(area)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 3);
// Select bands
var nir = images.select('B6'); // Band B6 is NIR in Landsat 8
var red = images.select('B4'); // Red band
var swir = images.select('B5'); // Short-wave infrared band
// Function to process and calculate indices for each image
function processImage(image) {
// Select bands within the function
var nir = image.select('B6');
var red = image.select('B4');
var swir = image.select('B5');
// Calculate NDVI
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');
// Calculate other texture measures
var rsi = ee.Terrain.slope(swir);
var contrast = swir.reduceRegion({
reducer: ee.Reducer.stdDev(),
geometry: area,
scale: 30
});
var entropy = swir.entropy({kernel: ee.Kernel.square(3)});
var granularity = swir.glcmTexture('mean');
var correlation = swir.glcmTexture('correlation');
// Combine texture measures (correct mean calculation)
var textureIndex = ee.Image.cat([rsi, contrast.get('B5'), entropy, granularity, correlation]);
// Add bands and indices to the image
return image.addBands(ndvi).addBands(rsi).addBands(contrast).addBands(entropy).addBands(granularity).addBands(correlation).addBands(textureIndex);
}
// Apply the function to each image in the collection
var processedImages = images.map(processImage);
// Filter processed images for valid values
processedImages = processedImages.filter(ee.Filter.maskNotNull(processedImages.select('B6')));
// Calculate the mean of each band in each image
var textureIndex = ee.ImageCollection([processedImages.select('RSI'), processedImages.select('contrast'), processedImages.select('entropy'), processedImages.select('granularity'), processedImages.select('correlation')]);
var textureIndexList = [];
for (var i = 0; i < textureIndex.size(); i++) {
var image = textureIndex.get(i);
// Check for valid values and convert to ee.Number if needed
var meanValue;
if (image.reduceRegion({reducer: ee.Reducer.count()}, area, 30).get('B5') > 0) {
meanValue = image.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: area,
scale: 30
}).get('B5');
meanValue = ee.Number(meanValue); // Ensure the value is an ee.Number
} else {
meanValue = ee.Number.NaN();
}
textureIndexList.push(meanValue);
print(meanValue); //
LEMBRANDO NÃO SOU EXPERT EM JAVASCRIPT. Alguém poderia me ajudar? :( tentei consultar as IAS da vida, mas nenhuma consegue...
Beta Was this translation helpful? Give feedback.
All reactions