3

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') Export.image.toDrive({ image:ndvi, description: 'ndvi', scale: 30, // region: geometry, maxPixels:34089663741 }); 

1 Answer 1

3

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') Export.image.toDrive({ image:toexport, description: 'ndvi', scale: 30, maxPixels:1e13 }); 

In Python:

import ee ee.Initialize() 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 = { 'fileNamePrefix':'NAME', 'folder':'FOLDER', 'image':toexport.toFloat(), // cast bands 'description': 'ndvi', 'scale': 30, 'maxPixels':1e13 } ee.batch.Export.image.toDrive(**params) 
6
  • 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 Commented Aug 3, 2018 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 Commented Aug 3, 2018 at 16:13
  • Thanks for your reply. Please update me the code ASAP.very urgent Commented Aug 3, 2018 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. Commented Aug 3, 2018 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. Commented Aug 3, 2018 at 18:27

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.