I'm trying to find area covered by plants on my study area, but I'm getting this error:
ndvi.filterDate is not a function
This is my code:
// Define a region of interest (i.e. an imported shapefile or a polygon drawn in GEE)
var cliplayer = clipper;
var roi = clipper;
// var s2 = ee.ImageCollection("LANDSAT/LT05/C01/T1")
// .filterDate('1995-05-01', '2003-07-31')
// .filterBounds(roi)
// .filter(ee.Filter.eq('WRS_PATH', 172))
// .filter(ee.Filter.eq('WRS_ROW', 71))
// .select("B2","B3","B4")
// .limit(35)
// print(s2);
// //I set a limit to test the code so it would not return too many results...remove to see all results
// function addImage(image) { // display each image in collection - clipped to roi
// var id = image.id
// var imagee = ee.Image(image.id)
// var clipimage = imagee.clip(clipper)
// // Map.addLayer(clipimage, {bands: ['B4', 'B3', 'B2'], min: 6000, max: 12000}, id)
// Map.addLayer(clipimage, {bands: ['B5', 'B4', 'B3'], min: 0, max: 255}, id)
// }
// s2.evaluate(function(s2) { // use map on client-side
// s2.features.map(addImage)
// })
//////////////////////////////////NDVI Calculation for Plants//////////////////////////
Map.centerObject(roi, 13);
var image = ee.Image(ee.ImageCollection("LANDSAT/LT05/C01/T1")
.filterDate('1995-05-01', '2003-07-31')
.sort('CLOUD_COVER')
.first());
// print (image);
// Compute the Normalized Difference Vegetation Index (NDVI).
var ndvi = image.normalizedDifference(['B5', 'B4']);
// //Thresholding based mapping
// var waterbody = ndvi.lte(0);
// // print(waterbody)
//////////////////////Calculating area//////////////////////////////
var s2image = ndvi.filterDate('1995-05-01', '2003-07-31').mean();
var s2cliped = s2image.clip(cliplayer).select("B2","B3","B4");
var area = ee.Image.pixelArea().divide(1e5).addBands(s2cliped).reduceRegion({
reducer : ee.Reducer.sum(),
geometry : cliplayer,
scale : 10,
bestEffort: true,
});
print(area)
Code link is here: https://code.earthengine.google.com/15024379590dfebb0ce49ffdfd56ecd4
filterDate
is a method of anImageCollection
not anImage
.