1

Apologies for my ignorance but I am brand new to using GEE and javascript. I've searched for some time for solutions but can't find/understand what I'm looking for.

I have 4 shapefiles which each contain a series of polylines (named below as 'icefalls', 'tongues' etc.). The goal is to extract mean and max slope data along these lines and have the data exported in CSV.

I have imported the shapefiles into GEE as feature collections and displayed them on a DEM, which also has slope calculated from it. I've then used reduceRegions to get the mean and max values - I've done this seperately for each feature collection, but if this can be streamlined into a single operation please enlighten me.

I then create another variable to combine the above variables into one for printing to the console and (I had hoped) for export to a single CSV. The console is saying this new variable is a List with 4 elements and is hence failing to export to CSV with the error: "Unknown element type provided: object. Expected: ee.Image, ee.ImageCollection, ee.FeatureCollection or ee.Element."

So how can I export the data in this collection of feature collections (mean max values for 4 sets of polylines) to a single CSV file?

If anyone could suggest some better ways of doing this I'd be very appreciative as I'm a bit stuck! Here's some of the code:

// Add the DEM to the map, then calculate and add slope
Map.addLayer(dem, {min: 0, max: 6000}, 'DEM');
var slope = ee.Terrain.slope(dem);
Map.addLayer(slope, {min: 0, max: 90}, 'slope');

// Add the icefall lines to the map
Map.addLayer(icefalls, {color: 'cyan'}, 'EU Icefalls');
Map.addLayer(tongues, {color: 'blue'}, 'EU Tongues');
Map.addLayer(non_icefalls, {color: 'orange'}, 'EU Non-ogive Icefalls');
Map.addLayer(non_tongues, {color: 'red'}, 'EU Non-ogive Tongues');

// Create variable for joint reducer that finds both the mean and max of data
var reducers = ee.Reducer.mean().combine({
  reducer2: ee.Reducer.max(),
  sharedInputs: true
});

// Extract slope values along the lines
var icefall_slope = slope.reduceRegions({
  collection: icefalls,
  reducer: reducers,
  scale: 30
});

var tongue_slope = slope.reduceRegions({
  collection: tongues,
  reducer: reducers,
  scale: 30
});

var non_icefall_slope = slope.reduceRegions({
  collection: non_icefalls,
  reducer: reducers,
  scale: 30
});

var non_tongue_slope = slope.reduceRegions({
  collection: non_tongues,
  reducer: reducers,
  scale: 30
});

//Combine above variables into 1 single variable containing the data within each line set.
var slopes = [
  icefall_slope,
  tongue_slope,
  non_icefall_slope,
  non_tongue_slope
  ];



// Show the results in the console
print ('Slopes', slopes);


// Export the results to a csv file and upload to Drive. 
Export.table.toDrive({
  collection: slopes,
  description: 'Test_export',
  fileFormat: 'CSV'
});

1 Answer 1

1

It sounds like you want to merge() the collections together into 1 big one. The easiest way to do that is:

c1.merge(c2).merge(c3)...  

but you can also convert the list of collections into a collection of collections, and then flatten() it.

var slopes = ee.FeatureCollection([
   icefall_slope,
   tongue_slope,
   non_icefall_slope,
   non_tongue_slope
]).flatten()

Both of these assume that all of the features in all of the collections have the same property names. If that's not the case, you'll have to specify all of the property names you want to export in the Export using the selectors argument.

1
  • Thank you Noel, both options work great, I was close through further research but hadn't quite figured out the exact syntax. Many thanks!
    – WillW
    Feb 15, 2021 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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