I'm trying to get population density data from Google Earth Engine but i get an error.
Line 17: gpw_roi.reduceRegions is not a function
// Load GPW population count dataset
var gpw = ee.ImageCollection('CIESIN/GPWv4/population-count');
// Define the area of interest (AOI) using a polygon geometry
var aoi = ee.Geometry.Polygon([
[-74.1, 40.6],
[-74.1, 40.7],
[-73.9, 40.7],
[-73.9, 40.6],
]);
// Filter the GPW dataset to the AOI
var gpw_roi = gpw.filterBounds(aoi);
// Function to calculate population for each feature in the collection
var calculatePopulation = function(feature) {
var population = gpw_roi.reduceRegions({
reducer: ee.Reducer.sum(),
collection: feature.geometry(),
scale: 1000, // Scale in meters (adjust based on your area size and resolution)
});
return feature.set('population_count', population.first().get('population-count'));
};
// Map the function over the FeatureCollection and calculate population for each area
var populationCounts = gpw_roi.map(calculatePopulation);
// Print the population counts
print('Population Counts:', populationCounts);
What could be wrong with the script? How can i get the population count?