I can export NDVI values to CSV file. But I couldn't export RGB values(b2,,b3,b4) to csv file and RGB values must be in range 0-255.

var geometry = 
    /* color: #d63000 */
    /* displayProperties: [
        "type": "rectangle"
    ] */
        [[[26.9559366037084, 39.42848463948233],
          [26.9559366037084, 39.41562180312237],
          [26.971214466257226, 39.41562180312237],
          [26.971214466257226, 39.42848463948233]]], null, false);

var image = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
    .filterDate('2020-06-01', '2020-8-31')

var palette = [
  'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
  '74A901', '66A000', '529400', '3E8601', '207401', '056201',
  '004C00', '023B01', '012E01', '011D01', '011301']
function addNdvi(img){
    var ndvi = img.normalizedDifference(['B5','B4']).rename('ndvi');
    return img.addBands(ndvi);
var ndvi= addNdvi(image.clip(geometry));
Map.addLayer(ndvi,{bands: ['ndvi'], palette: palette},'ndvi');
Map.addLayer(image.clip(geometry),{bands: ['B4', 'B3', 'B2'], max:0.3}, 'rgb');

var ndviFeatures = ee.FeatureCollection(ee.List(ndvi
    reducer: ee.Reducer.toList(),
    geometry: geometry,
    scale: 10
  .map(function (ndvi) {
    return ee.Feature(null, {ndvi: ndvi})``

var rgbFeatures = ee.FeatureCollection(ee.List(image
    reducer: ee.Reducer.toList(),
    geometry: geometry,
    scale: 10
  .map(function (rgb) {
    return ee.Feature(null, {rgb: rgb})

print('# rgb of pixels',rgbFeatures.size())
print('# ndvi of pixels',ndviFeatures.size())

  collection: rgbFeatures,
  description: 'dene',
  fileFormat: 'CSV',
  selectors: ['B4', 'B3', 'B2']

  collection: ndviFeatures,
  description: 'ndvi',
  selectors: ['ndvi']

1 Answer 1


You didn't specify how you wanted your CSV file to be formatted, so here's one approach simply creating a column for each of the three bands:

var bands = ['B2', 'B3', 'B4']
var rgbFeatures = ee.FeatureCollection(
  .multiply(255) // 0-1 to 0-255
    reducer: ee.Reducer.toList(),
    geometry: geometry,
    scale: 30
  .map(function (values) {
    return ee.Feature(null, ee.Dictionary.fromLists(bands, values))


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.