google-earth-engine – Extracting MODIS Data Values at Point Coordinates Using Google Earth Engine

extractgoogle-earth-enginemodispoint

I'm trying to extract from the MODIS collection MOD11A1006 band "LST_Day_1km" at one point coordinates the value of each image in the collection together with the date, and hour of the image and export this data to a CSV file. However, if I'm not mistaken, the code bellow gets the the "date" and "hour" when the image was taken, but for some reason I could not extract the "LST_Day_1km" band value at the point coordinates.
How this could be extracted?

// Site coords
var siteCoords_features = [
ee.Feature(ee.Geometry.Point( -69.282000066708,-12.831999897556432), {name: 'site'})];

// Creates a FeatureCollection from coords
var pt_collection = ee.FeatureCollection(siteCoords_features);
print('Point', pt_collection)
Map.addLayer(pt_collection)
Map.centerObject(pt_collection, 10)

// Modis Collection
var startDate = ee.Date.fromYMD(2015,1,1);
var endDate = ee.Date.fromYMD(2020,12,31);
var dataset = ee.ImageCollection('MODIS/006/MOD11A1')
                  .filterDate(startDate, endDate)
                  .filterBounds(pt_collection.geometry())
                   .select('LST_Day_1km');
 print("Collection",dataset)                 

// Extracted band Scale to Kelvin and convert to Celsius
var modLSTc = dataset.map(function(img) {
  return img
    .multiply(0.02)
    .subtract(273.15)
   .copyProperties(img, ['system:time_start']);
});
print('Modis Image Colection processed:', modLSTc);
//Map.addLayer(modLSTc)

var geometry = pt_collection.geometry();
var extractData = function(img){
    var stats = img.reduceRegion({
      geometry: geometry,
      scale: 30,
      reducer: ee.Reducer.first()})
    return ee.Feature(geometry, {
      value: img.get('LST_Day_1km'), 
      hourStart: img.get('system:time_start'),
      hourEnd : img.get('system:time_start'),
      date: img.get('system:index'),
      lat: geometry.coordinates().get(0),
      lon: geometry.coordinates().get(1),
      })
    
}
var outputData = modLSTc.map(extractData)
print('output',outputData)


/*
// Export
Export.table.toDrive({
  collection: outputData,
  folder: 'GEE_results',
  fileNamePrefix: 'MODIS_LST_2015_2020',
  fileFormat: 'CSV',
  selectors: ['date', 'hourStart','hourEnd' ,'value', 'lat', 'lon']})
*/        

Best Answer

When you are working with these time series collections, you have to be sure that they are not empty at considered geometry. First of all, I "added" as layer first image of modLSTc without any result. So, afterward, I could add modLSTc mean indicating this Image Collection is not empty. Now, I could corroborate that you didn't extract the "LST_Day_1km" band value at the point coordinates because value is in the new created variable stats; not in img. So, I modified your code as follows for retrieving 2182 corresponding values (including nulls) for 'LST_Day_1km' and correct value for 'system:time_end'.

// Site coords
var siteCoords_features = [
ee.Feature(ee.Geometry.Point(-69.282000066708,-12.831999897556432 ), {name: 'site'})];

// Creates a FeatureCollection from coords
var pt_collection = ee.FeatureCollection(siteCoords_features);
print('Point', pt_collection);
Map.addLayer(pt_collection);
Map.centerObject(pt_collection, 10);

// Modis Collection
var startDate = ee.Date.fromYMD(2015,1,1);
var endDate = ee.Date.fromYMD(2020,12,31);
var dataset = ee.ImageCollection('MODIS/006/MOD11A1')
                  .filterDate(startDate, endDate)
                  .filterBounds(pt_collection.geometry())
                   .select('LST_Day_1km');

print("Collection",dataset);               

//Map.addLayer(dataset.first());

// Extracted band Scale to Kelvin and convert to Celsius
var modLSTc = dataset.map(function(img) {
  return img
    .multiply(0.02)
    .subtract(273.15)
   .copyProperties(img, ['system:time_start', 'system:time_end']);
});

print('Modis Image Colection processed:', modLSTc);
//Map.addLayer(modLSTc.mean());

var geometry = pt_collection.geometry();
var extractData = function(img){
    var stats = img.reduceRegion({
      geometry: geometry,
      scale: 30,
      reducer: ee.Reducer.first()});

    return ee.Feature(geometry, {
      value: stats.get('LST_Day_1km'), 
      hourStart: img.get('system:time_start'),
      hourEnd : img.get('system:time_end'),
      date: img.get('system:index'),
      lat: geometry.coordinates().get(0),
      lon: geometry.coordinates().get(1),
      });
    
};

var outputData = modLSTc.map(extractData);
print('output',outputData);

// Export
Export.table.toDrive({
  collection: outputData,
  folder: 'GEE_results',
  fileNamePrefix: 'MODIS_LST_2015_2020',
  fileFormat: 'CSV'});

After running above code in GEE code editor, an extract of obtained CSV can be observed as follows.

enter image description here

It can also be observed there are many missing values for temperature (column highlighted with red rectangle).

Related Question