0

I tried downloading the mean NO2 value along with the latitude and longitude of each pixel covered in a specific region in a CSV file from Google-earth-engine. However, the following code can download the data with the system index but not the latitude and longitude.

// Set the start and end dates for the data
var startDate = '2021-03-01';
var endDate = '2021-05-31';

// Set the region of interest
var region = ee.Geometry.Polygon(
    [[[-98.00, 23.00],
      [-98.00, 17.00],
      [-89.00, 17.00],
      [-89.00, 23.00]]], null, false);
Map.addLayer(region)
Map.centerObject(region, 6)

// Create a date filter to get data from the specified month
var dateFilter = ee.Filter.date(startDate, endDate);

// Get the mean data for the specified month and region
var dataset = ee.ImageCollection('COPERNICUS/S5P/NRTI/L3_NO2')
          .select('NO2_column_number_density')
          .filterBounds(region)
          .filter(dateFilter)

var meanData = dataset.mean().clip(region);

var band_viz = {
  min: 0.00001,
  max: 0.00009,
  palette: ["2f4858","33658a","86bbd8","f6ae2d","f26419"]
};

Map.addLayer(meanData, band_viz)

// Extract the pixel values, latitude, and longitude
var features = meanData.sampleRegions({
collection: region,
properties: ['NO2'],
scale: 10000
});

// Export the data to a CSV file
Export.table.toDrive({
collection: features,
fileFormat: "CSV",
folder: "gee",
fileNamePrefix: "mean_tropomi_no2_data" 
});    

1 Answers1

0

Either add geometries: true to the sampleRegions function to get geometries (as Points) or add a ee.Image.pixelLonLat() to the meanData layer to get the values as columns.

var features = meanData.addBands(ee.Image.pixelLonLat()).sampleRegions({
Noel Gorelick
  • 489
  • 2
  • 10