-1

I am trying to export the ground elevation (elev_lowestmode) values from the GEDI L2A monthly raster data set (ee.ImageCollection("LARSE/GEDI/GEDI02_A_002_MONTHLY").

I need the elevation values and the corresponding lat and long as a CSV file. I've tried many ways to export them. I am getting the elevation values but not the lat and long. The due date of my project is expiring.

This is one of the codes I tried but didn't work. I'm getting only 25 elevation values and the code for getting lat an long showed many errors. so i haven't added that in this code https://code.earthengine.google.com/c000e3f6901b63d3a3affc67dc279bc8

  return im.updateMask(im.select('quality_flag').eq(1))
      .updateMask(im.select('degrade_flag').eq(0));
};
var gedi = ee.ImageCollection('LARSE/GEDI/GEDI02_A_002_MONTHLY')
                  .map(qualityMask)
                  .select('elev_lowestmode');

var gediVis = { min: 1, max: 60, palette: 'darkred,red,orange,green,darkgreen', }; // Map.setCenter(-74.803466, -9.342209, 10); Map.addLayer(gedi, gediVis, 'elev_lowestmode');

// Define a function to clip imagecollection. var ImageCollection = ee.ImageCollection('LARSE/GEDI/GEDI02_A_002_MONTHLY') var clip_fn = function(image) { var ClippedImage = image.clip(geometry);   return ClippedImage; }; // Map the function over the collection. var ImageCol_clip = ImageCollection.map(clip_fn);

// Clip the GEDI L2 dataset to the region of interest var clippedGedi = gedi.map(function(img) { return img.clip(geometry); });

// Create the digital elevation model by taking the mean of all the images var dem = clippedGedi.mean().int();

// Create a feature collection of pixels in the dem var pixels = dem.reduceToVectors({ geometry: geometry, scale: 1000, geometryType: 'polygon', eightConnected: false, labelProperty: 'elevation', });

Map.addLayer(ImageCol_clip); // Clip the GEDI L2 dataset to the region of interest var clippedGedi = gedi.map(function(img) { return img.clip(geometry); });

// Export the feature collection as a CSV file Export.table.toDrive({ collection: pixels, description: 'ALP elevation', selectors: ('elevation'), fileFormat: 'CSV' });

I know this code needs a lot of modification but this is the best i could come up with as of now.

BERA
  • 72,339
  • 13
  • 72
  • 161

1 Answers1

0

One way would be change this in your code:

var pixels = dem.reduceToVectors({
  geometry: geometry,
  scale: 1000,//1000m is the reason why you have only 25,to get ~each pixel value, you must change it to 25m(GEDI resolution)   
  geometryType: 'centroids',//I would suggest the centroid of the pixels 
  eightConnected: false,
  labelProperty: 'elevation',
});

// Export the feature collection as a CSV file Export.table.toDrive({ collection: pixels, description: 'ALP elevation', selectors: ['elevation','.geo'],//add ".geo" to get the coordinates or simply deleted the selectors to get all properties fileFormat: 'CSV' });

If you want the lat/long as an independent attribute, just add this before to export:

//get lat long
var proj = dem.select([0]).projection()
var latlon = ee.Image.pixelLonLat()
dem = dem.addBands(latlon.select('longitude','latitude'))

//extract lat lon pixels=dem.select('longitude').reduceRegions(pixels, ee.Reducer.mean().setOutputs(['long']), 25) pixels=dem.select('latitude').reduceRegions(pixels, ee.Reducer.mean().setOutputs(['lat']), 25);

To know more about ee.Image.reduceToVectors check this

Here an example code

  • @david, This code seems to be working. but all the values that I'm getting are negetive. and they too in -90,-80,-60 ranges. So I want to know if I want to get the ground elevation is there a better value to use rather than the elev_lowestmode in gedi data. I thought of using rh1 or rh25. Will that work fine? – nawra parveen Feb 09 '23 at 13:07
  • @David, can i get the lat and long as seperate tables instead of it in .geo? – nawra parveen Feb 10 '23 at 08:42
  • @nawraparveen I’m not sure of the answer about you first comment. But for the second comment, sure!! I updated my answer explaining how to extract lat/lon as independent attribute; also, the link of the example was updated. If you find it useful, consider mark the answer as accepted for future references. – J. David Urquiza-Muñoz Feb 10 '23 at 19:54
  • @david sure thankyou – nawra parveen Feb 16 '23 at 05:48