1

Following GEE code was used for producing an ee.List of [year, month, day, daily precipitation] for CHIRPS/DAILY images filtered by date ('2015-01-01', '2016-01-01') and by using a point ee.Reducer (location of my weather station).

//Selecting Image Collection of dayly precipitation
var chirps = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY");

var precip = chirps
  .filterDate('2015-01-01', '2016-01-01'); //366 days (leap year)

var count = precip.size();

// Print the filtered precipitation ImageCollection. 
print('precipitation series:', precip);

var getDatePrecip = function(image) {
  // weather station place: Valle de la Pascua 
  var p = ee.Geometry.Point(-66.00, 9.22);

  // Reducing region and getting value
  var value = ee.Image(image)
    .reduceRegion(ee.Reducer.first(), p).get('precipitation');

  var time = ee.Image(image).get('system:time_start');

  // Return the time (in milliseconds since Jan 1, 1970) as a Date
  var precipit_list = ee.Date(time)
    .format()
    .slice(0,10)
    .split('-')
    .add(value);

  return precipit_list;
};

var precipit_list = precip.toList(count).map(getDatePrecip);

print(precipit_list);

Result, as expected, it is an ee.List with following structure:

.
.
.
132:
["2015","05","13",1.8483211994171143]
133: 
["2015","05","14",0]
134: 
["2015","05","15",0]
135: 
["2015","05","16",0]
136: 
["2015","05","17",0]
137: 
["2015","05","18",5.3127264976501465]
138: 
["2015","05","19",10.625452995300293]
139: 
["2015","05","20",5.3127264976501465]
140: 
["2015","05","21",5.391742706298828]
141: 
["2015","05","22",0]
142: 
["2015","05","23",0]
143: 
["2015","05","24",0]
144:
.
.
.

and it can be also flattened to following structure by using flatten ee.List method:

.
.
.
551: 
5.3127264976501465
552: 
2015
553: 
05
554: 
19
555: 
10.625452995300293
556: 
2015
557: 
05
558: 
20
559: 
5.3127264976501465
560: 
2015
561: 
05
562: 
21
563: 
5.391742706298828

.
.
.

My question is how can I export to Drive whatever of these ee.Lists in GEE? I tried out several approach (by using Export.table.toDrive) without any succeed. I could not find out any method to convert an ee.List in a FeatureCollection.

2

Just add these lines below your code, run it and start the task on the "Tasks" tab.

// weather station place: Valle de la Pascua 
var p = ee.Geometry.Point(-66.00, 9.22);

var myFeatures = ee.FeatureCollection(precipit_list.map(function(el){
  el = ee.List(el); // cast every element of the list
  var geom = p;
  return ee.Feature(geom, {
    'year':ee.Number(el.get(0)), 
    'month':ee.Number(el.get(1)),
    'day':ee.Number(el.get(2)),
    'value':ee.Number(el.get(3))
  });
}));

Map.addLayer(myFeatures); // see the result
Map.centerObject(myFeatures);

// Export features, specifying corresponding names.
Export.table.toDrive(myFeatures,
"myTask",
"myExportFolder",
"myList", 
"CSV");
  • 1
    Thanks for your answer. It produces same result with normal or flattened list. With 'SHP' extension produces a point shapefile with 365 records or features. It was only a test because this makes no sense. – xunilk Nov 9 '18 at 19:38

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.