When I download Analysis results from Google Earth Engine, the image is exported in to google drive but it does not have a color palette. How do i add color palette with the exported image using earth engine.

var landcover_roi = composite.clip(ft);
var ndvi =landcover_roi.normalizedDifference(['B8', 'B4']) ;
Map.addLayer(landcover_roi,{bands: ['B6', 'B4', 'B3'], min: 0, max: 0.3}, 'From Fusion Table');

// Make a palette: a list of hex strings.
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
               '74A901', '66A000', '529400', '3E8601', '207401', '056201',
               '004C00', '023B01', '012E01', '011D01', '011301'];

// Center the map
Map.setCenter(87.32,22.40, 6);

Map.addLayer(ndvi,{min: 0, max: 1, palette: palette},'Sentinel-2 NDVI')
  description: 'ndvi',
  scale: 30,
 // region: geometry,

Use visualize function

// var landcover_roi = composite.clip(ft);
var landcover_roi = ee.Image('COPERNICUS/S2/20151001T142056_20161104T062106_T18GYP')
var ndvi =landcover_roi.normalizedDifference(['B8', 'B4']);

// Make a palette: a list of hex strings.
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
               '74A901', '66A000', '529400', '3E8601', '207401', '056201',
               '004C00', '023B01', '012E01', '011D01', '011301'];

// make a visualizing variable
var vis = {min: 0, max: 1, palette: palette, bands:['nd']};

// create a new image that will have 'vis-red', 'vis-green' and 'vis-blue' bands and add original value of ndvi
var toexport = ndvi.visualize(vis).addBands(ndvi)

Map.addLayer(ndvi, vis,'Sentinel-2 NDVI')
  description: 'ndvi',
  scale: 30,

In Python:

import ee

landcover_roi = ee.Image('COPERNICUS/S2/20151001T142056_20161104T062106_T18GYP')

ndvi =landcover_roi.normalizedDifference(['B8', 'B4'])

# Make a palette: a list of hex strings.
palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
           '74A901', '66A000', '529400', '3E8601', '207401', '056201',
           '004C00', '023B01', '012E01', '011D01', '011301']

palette = ','.join(palette)

# make a visualizing variable
vis = {'min': 0, 'max': 1, 'bands':'nd', 'palette': palette}

# create a new image that will have 'vis-red', 'vis-green' and 'vis-blue' bands and add original value of ndvi
toexport = ndvi.visualize(**vis).addBands(ndvi)

params = {
    'image':toexport.toFloat(), // cast bands
    'description': 'ndvi',
    'scale': 30,

| improve this answer | |
  • Thanks Rodrigo this worked in GEE but this same thing doesnt work in python api of GEE. . toexport = ndvi.visualize(vis).addBands(ndvi)- For this line it shows please add 1-3 bands to visualize. please help me to solve this problem – Sohini Goswami Aug 3 '18 at 16:07
  • Yes, the python API works a little different in the visualize method. I'll update the answer adding the way to do it in Python – Rodrigo E. Principe Aug 3 '18 at 16:13
  • Thanks for your reply. Please update me the code ASAP.very urgent – Sohini Goswami Aug 3 '18 at 16:15
  • hi,thanks for your prompt reply. i have implemented the code. The earth engine is giving an error when I run this code in python api for GEE.--Error: Exported bands must have compatible data types; found inconsistent types: Byte and Float32. – Sohini Goswami Aug 3 '18 at 17:30
  • I have multiplied the ndvi value with 100 and casted it to an integer. Though the code is running ,but the downloaded image is still showing black n white image. – Sohini Goswami Aug 3 '18 at 18:27

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.