0

I'm trying to use Export function from the Google Earth Engine API but it does not recognize the function.

var p1 = ee.Feature(ee.Geometry.Point([-97.44070668220519, 41.93324324360744]));
var p2 = ee.Feature(ee.Geometry.Point([-93.92508168220519, 40.612183748474436]));
var p3 = ee.Feature(ee.Geometry.Point([-97.08914418220519, 38.5807048157763]));

var col = ee.FeatureCollection([p1, p2, p3]);
var col_list = col.toList(col.size());

//print(col);

//Map.addLayer(col);

var startYear = '2008';
var endYear = '2018';

var dataset = ee.ImageCollection('NASA/GPM_L3/IMERG_MONTHLY_V06')
    .filterDate(startYear, endYear)
    .select('precipitation');
    
//print(dataset);

var dataset_list = dataset.toList(dataset.size());

var year_list = ee.List.sequence(ee.Number.parse(startYear), ee.Number.parse(endYear).subtract(1));

var leapYear_list = year_list.map( function leapYear(year) {
  
  return ee.Number(year).mod(4).eq(0).and(ee.Number(year).mod(100).neq(0)).or(ee.Number(year).mod(400).eq(0));
  
});

//print(leapYear_list);

var monthNumberDays = leapYear_list.map(function setYearsNumberDays (ele) {

  return ee.Algorithms
    .If(ee.Number(ele).eq(1), [31,29,31,30,31,30,31,31,30,31,30,31], 
                              [31,28,31,30,31,30,31,31,30,31,30,31]);
  
}).flatten();

var allDates = ee.List(dataset.aggregate_array('system:time_start'));

var allDatesSimple = allDates.map(function(date){
  return ee.Date(date).format().slice(0,7);
  });

//print(allDatesSimple);

var getMonthlyValues = col_list.map(function (feat) {
  
  var getPrecipit = function(image) {

    // Reducing region and getting value
    var value_ppt = ee.Image(image)
      .reduceRegion(ee.Reducer.mean(), ee.Feature(feat).geometry())
      .get('precipitation');

    return ee.Number(value_ppt).multiply(24);  //mm/day

  };
  
  var ppt_list = dataset_list.map(getPrecipit);
  
  var monthlyValues = ppt_list.map(function (ele){
  
    var idx = ppt_list.indexOf(ele);
    
    return ee.Number(ele).multiply(monthNumberDays.get(idx));
    
  });
  
  return monthlyValues;
  
});

var list = ee.List.sequence(0, ee.Number(allDatesSimple.size()).subtract(1));

var myFeatures = ee.FeatureCollection(list.map(function(el){
  el = ee.List(el); // cast every element of the list
  return ee.Feature(null, {
    'date': allDatesSimple.get(el),
    'p1': ee.List(getMonthlyValues.get(0)).get(el),
    'p2': ee.List(getMonthlyValues.get(1)).get(el),
    'p3': ee.List(getMonthlyValues.get(2)).get(el),
    
  });
}));

//print(myFeatures);

// Export features, specifying corresponding names.
Export.table.toDrive(myFeatures,
"export_ppt", //my task
"GEE_Folder", //my export folder
"ppt_monthly",  //file name
"CSV");

var encodedUri = encodeURI(myFeatures);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");
document.body.appendChild(link); // Required for FF

link.click(); // This will download the data file named "my_data.csv".

I'm initializing the Google Earth Engine and it seems it identifies the ee.* functions but not the non ee ones.

When I run this, it gives me a message saying that Export is not defined.

Please help.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • `Export` is indeed not defined in your code, you're doing `Export.table...` but there is no definition for it anywhere in the code you shared. – M0nst3R Aug 18 '23 at 14:16
  • How do you define it? I thought you just needed to import the google earth api...- and that's what I'm doing. I have a lot more of code before that. i authenticate into the cloud and then do ee.initialize() and then run the code – Ndilokelwa Luis Aug 18 '23 at 15:46
  • Would you be able to verify and share in your question how you are importing `Export`? Maybe you are doing it incorrectly. – M0nst3R Aug 18 '23 at 15:54
  • I'm just importing the google earth javascript api. I'm not declaring anything on it. Because this is one method from google earth and I don't declare anything to use the ee.* methods and functions, I though I didn't need to do anything to declarethe Export – Ndilokelwa Luis Aug 18 '23 at 16:34

0 Answers0