I am trying to export an image collection to a 2D table where :

  • axis 0 are pixels over the collection
  • axis 1 are bands from the image collection

I would loose spatial information, as pixels would be unordered which is OK. It could look like this (pixel Id unecessary):

example of table

I found the function toArray() that seems to do exactly what I want, but I am unable to export it to a CSV file or any type of format

// Load a Landsat collection, select the bands of interest.
var imageCol = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  .select(['B1', 'B2', 'B3'])
  .filterDate('2017-09-01', '2017-09-02');

// Make an Array Image, with a 1-D Array per pixel.
var im_array = imageCol.toArray();

I have tried to transform this into a featureCollection but it doesn't work :

var im_feats = im_array.reduceToVectors()

I would have then export it in CSV with Export.table (it would be quite a heavy file):

  collection: im_feats ,
  fileFormat: 'CSV'

Am I taking a wrong approach ? Is there a trick to get around this issue ?


This is a very strange thing to do, but I'm sure you've got your reasons.

var pixels = image.reduceRegion({
  reducer: ee.Reducer.toList(),
  geometry: geometry,
  scale: 100
}) // A Dictionary with pixel values by band name

var numberOfPixels = ee.List(pixels.values().get(0)).size() // Pixel count for first band
var bandNames = image.bandNames()
var features = ee.FeatureCollection(
  ee.List.sequence(0, numberOfPixels.subtract(1))
    .map(function (i) {
      return bandNames.iterate(function (bandName, feature) {
        bandName = ee.String(bandName)
        var pixelValue = ee.List(pixels.get(bandName)).get(i)
        return ee.Feature(feature)
          .set(bandName, pixelValue)
      }, ee.Feature(ee.Geometry.Point([0, 0])))
) // Turn Dictionary into FeatureCollection


| improve this answer | |
  • Thanks, this has worked for me. I have an alternative way I am using combining exporting tif from gee and data processing outside of gee (I do it in python). I was hoping the technique native to gee would be faster than the mixed one, but it is roughly 10 times slower. – spalice Dec 14 '19 at 11:00

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.