I have script that does the enxt procedures:
- create imagecollection from Landsat7
- clip the images according to specific geometry and calculte NDVI for each one
- filter the rasters according to the number of pixels (I don't want to have small rasters)
- creates images by calculte for each year the mean NDVI value.
- Creates timeseries graph based on years.
Now I want to create the 6th step which is to calculte for each raster how many pixels got NDVI value greater than 3. because I have one image per year I want to create a for loop that will count those pixels for each year and will produce a table. I have written a code but it is not good because it seems like javascript doesn't understand that "i" is image. also, I don't think this code will prosuce a table in the end.
This is my code:
// Declare years of interest
var years = ee.List.sequence(2000, 2013);
// Map a function to select data within the year and apply mean reducer
var byYear = ee.ImageCollection.fromImages(
years.map(function(y) {
return filter
.filter(ee.Filter.calendarRange(y, y, 'year'))
.reduce(ee.Reducer.mean())
.set('year', y);
})
);
var listOfImages =(byYear.toList(byYear.size()));
for (var i in listOfImages) {
var gt03 = i.gt(0.3).selfMask().rename('NDVI_gt03');
Map.addLayer(gt03,ndviParams,i);
//count the number of total pixels
var c03 = gt03.reduceRegion({
reducer: ee.Reducer.count(),
geometry: geometry,
crs: 'EPSG:4326',
scale: 30,
});
print(c03,year);
}
The wrror message:
i.gt is not a function
*I don't understand this error, because this code works when I do it on one image so why here it can't?
*maybe instead of lop I should use function? then what is the differences between them?
My end goal: To get a table or any calculation which shows for each year the number of pixels that were found in my raster with value higher than 0.3