1 | initial version |
Here is one way to export the pixel values of all bands in Google Earth Engine:
.getInfo()
method to retrieve the metadata for the image or collection."bands"
property of the metadata using .get("bands")
..getArray()
method to retrieve the pixel values for each band.Here is an example code snippet:
// Select an image or collection
var collection = ee.ImageCollection("COPERNICUS/S2_SR")
.filterDate("2021-01-01", "2021-12-31")
.filterBounds(geometry);
// Get the metadata for the image or collection
var metadata = collection.first().getInfo();
// Find the number of bands in the image or collection
var bandCount = metadata["bands"].length;
// Create an empty array to store the pixel values
var pixelValues = [];
// Iterate over all the bands and retrieve the pixel values
for (var i = 0; i < bandCount; i++) {
var bandName = metadata["bands"][i]["id"];
var bandValues = collection.select(bandName).toArray().getInfo();
// Add the pixel values to the array
pixelValues.push({
"band": bandName,
"values": bandValues
});
}
// Convert the pixel values to a CSV file and export it
var csv = "Band,Values\n";
pixelValues.forEach(function(data){
csv += data.band + ",";
data.values.forEach(function(value){
csv += value + ",";
});
csv += "\n";
});
Export.table.toDrive({
collection: ee.FeatureCollection([]),
description: "PixelValues",
fileFormat: "CSV",
fileNamePrefix: "PixelValues",
content: csv
});