i'm pretty new on GEE, so i hope someone can help me with this. As the title say, i'm looking for a way to calculate how many pixels i have inside a polygon. I tried to do it with reduceRegion and ee.Reducer.count() but this always give me error trying to do it with my collection.
I also tried to do it with ui.Chart.image.series using the same reducer. The result is a graph showing a constant number, which represent the number of pixels on the polygon, but it looks like most of the times is wrong because i checked the number of pixels manually, and both numbers doesn't match.
Here's the code. It's used to calculate the annual NDVI of a certain region, which is selected by the geometry (which is drawn with the map menu). Originally i used it to calculate the mean annual NDVI of the region (that's why i select the NDVI on the second line) changing the Reducer.count by Reducer.mean, but now i want to use it to know how many pixels are inside that polygon:
var dataset = ee.ImageCollection('MODIS/006/MOD13A1').filterDate('2019-1-1', '2019-12-31');
var ndvi = dataset.select('NDVI');
var chart = ui.Chart.image.series(ndvi, geometry, ee.Reducer.count(), 500, 'system:time_start').setOptions({
title: 'Annual NDVI',
vAxis: {title: 'NDVI'},
});
print(chart);
On the other hand, i tried to use this, but it gives error, saying that "dataset.reduceRegion is not a function":
var c = dataset.reduceRegion({
reducer: ee.Reducer.count(),
geometry: geometry,
scale: 500,
});
print(c);