4

I'm new to Google EE and I'm still figuring out how this works.

I want to export into a table the median values of LST from a shapefile for three years. I can do it for one year but If I set the time series more than a year the column with the median values in the exported CSV disappear.

Can you check if I'm missing something?

/* 1- Select Inputs */
var district = 'name of the district' ;
var folder = "path to the folder";
var mod11a1 = ee.ImageCollection("MODIS/006/MOD11A1");

/* 2- Input Region */
var aoi = ee.FeatureCollection('path to the shapefile')
  .filter(ee.Filter.eq('NAME', district));

var mod11a1 = ee.ImageCollection("MODIS/006/MOD11A1")
  .filter(ee.Filter.date('2018-01-01','2019-12-31'));  
  //.filter(ee.Filter.date('2019-01-01','2019-01-31'));

/* 3- Filter Image collections */
var lst = mod11a1.select('LST_Day_1km');

var imageCollection = lst.map(function(image){
  var result = image.reduceRegion({
    reducer: ee.Reducer.median(),
    geometry:aoi, 
    scale: 1000,
    maxPixels: 1e13
  });
  return ee.Image(image.setMulti(result)); 
});

/* 4 - Export  */
Export.table.toDrive({
  collection: imageCollection,
  description: district,
  folder: folder,
  fileFormat: 'CSV'
});
3

If you export to an Excel, the first feature is analysed for the contained properties and only the available properties are exported. If you extend the period, there are (possibly) null values for the LST and that property is not exported. You have two options:

Filter out the null values before exporting:

var imageCollection = mod11a1.map(function(image){
  var result = image.reduceRegion({
    reducer: ee.Reducer.median(),
    geometry:geometry, 
    scale: 1000,
    maxPixels: 1e13
  });
  return ee.Image(image.setMulti(result)); 
}).filter(ee.Filter.notNull([bandName]));

Or preset a value so there are no null values:

var imageCollection = mod11a1.map(function(image){
  return image.set({bandName: -999}) // set a non null value
        // copy properties
        .set(image.toDictionary(image.propertyNames()));
});
var imageCollection = imageCollection.map(function(image){
  var result = image.reduceRegion({
    reducer: ee.Reducer.median(),
    geometry:geometry, 
    scale: 1000,
    maxPixels: 1e13
  });
  return ee.Image(image.setMulti(result)); 
});
print('option 1',imageCollection)

You should then be able to export as you was used to. Link, with a sample geometry. Next time make sure your ode is reproducible by sharing a link or posting the code for the geometry.

| improve this answer | |
  • THANKS!!! Both methods work perfectly. Sorry about the no reproducible question, still figuring out the best way of posting, I'll try my best next time! – tcanelfe Mar 26 at 10:11
  • Another solution: link – Kuik Apr 29 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.