1

The code below extracts average rainfall for each US county for one given day and send the table result to drive. Now, how can I use iterate function to extract a time series for one year for example?

 // load precip data (mm, daily )
var precipCollection = ee.ImageCollection('OREGONSTATE/PRISM/AN81d')
                    .select('ppt')   // select  precip band only
                    .filterDate('2017-01-01'); // e.g. one day
print(precipCollection, 'precipCollection');

//reduce the image collection 
var dailyPrecip = precipCollection.reduce(ee.Reducer.sum());
print(dailyPrecip);

// visualize annual precipitation
var precipPal = ['white','blue','red','pink'] // store palette as variable               
Map.addLayer(dailyPrecip, {min: 1, max: 100, palette: precipPal}, 'precip');

////////////////////////////////////

// load regions: counties from a public fusion table, removing non-conus states
// by using a custom filter
var nonCONUS = [2,15,60,66,69,72,78] // state FIPS codes that we don't want
var counties = ee.FeatureCollection('ft:1ZMnPbFshUI3qbk9XE0H7t1N5CjsEGyl8lZfWfVn4')
        .filter(ee.Filter.inList('STATEFP',nonCONUS).not());
print(counties, 'counties');

// visualize
Map.addLayer(counties,{},'counties');  


// get mean precipitation values by county polygon
var countyPrecip = dailyPrecip.reduceRegions({
  collection: counties,
  reducer: ee.Reducer.mean(),
  scale: 4000 // the resolution of the prism dataset
});
print(countyPrecip);


// select features
var out = countyPrecip.select(['.*']);

// add a new column for date
out = out.map(function(feature){
return feature.set('date','2017-01-01');
});

// Table to Drive Export Example

Export.table.toDrive({
  collection: out,
  description: 'precip_by_county',
  folder: 'GEE',
  fileFormat: 'CSV'
});   
0

You can have a try about pkg_export.

 // load precip data (mm, daily )
var precipCollection = ee.ImageCollection('OREGONSTATE/PRISM/AN81d')
                    .select('ppt')   // select  precip band only
                    .filterDate('2017-01-01', '2018-12-31'); // e.g. two year
print(precipCollection.limit(3), 'precipCollection');

// load regions: counties from a public fusion table, removing non-conus states
// by using a custom filter
var nonCONUS = [2,15,60,66,69,72,78]; // state FIPS codes that we don't want
var counties = ee.FeatureCollection('ft:1ZMnPbFshUI3qbk9XE0H7t1N5CjsEGyl8lZfWfVn4')
        .filter(ee.Filter.inList('STATEFP',nonCONUS).not());
print(counties, 'counties');
Map.addLayer(counties, {}, 'counties');

/** pkg_export --------------------------------------------------------- */
var options = {
    reducers : ['mean'],  // 1th: non-buffer; 2th: buffer; Only one means no buffer
    buffer   : false,      // whether to use buffer
    list     : false, 
    folder   : '', // drive forder
    fileFormat: 'csv'      // 'csv' or 'geojson'
    // scale    : 1000
};

var pkg_export = require('users/kongdd/public:pkg_export.js');
pkg_export.spClipImgCol(precipCollection, counties, "precipCollection", options);

https://code.earthengine.google.com/8221ae9a4ae68a42f6b775a2cf84d6b2

2
  • it works well, but I wonder in this case how to only save some columns (i.e. select only the columns of interest or remove others)
    – Tikfa
    Jul 18 '19 at 9:07
  • You can select columns by selecting bands in counties and precipCollection first. If that works for you, please consider accept my answer. I need the score to vote. Jul 18 '19 at 14: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.