1

When I display my classification map, the colors don't line up with the variable that I want them to. For example, my forest category is represented as red (instead of my goal color-green), or my water category shows up as gray (instead of 'blue').

How do I order my color palette such that it corresponds with the classes appropriately?

This is my script so far in Google Earth Engine:

//Create a classification map. Classify the input imagery
var classified = composite.select(bands).classify(classifier);

//Define the palette for the land use classification

var palette = [
  '0000FF', // water (0)  -- blue
  'FFFF00', // cultivated (1)  -- yellow
  'DCDCDC', //  Settlement (2) -- gray
  'F0E68C', // Grasslands (3)--khaki
  '228B22', // forest  (4)-- forest green
  '000000', //clouds (5)-- black
  '808000', //intact veg (6)-- olive
  'FFA500', //impacted_veg (7)-- orange
  'DC143C', //mines (8)-- crimson
];

// Display the classification result and the input image.
Map.centerObject(K2C_aoi);
Map.addLayer(classified, {min: 0, max: 2, palette: palette}, 'Land Use Classification');
2

Earth Engine's visualization does not have a special case for integer or discrete values; the palette colors will be applied across the numerical range specified in the visualization parameters, with linear interpolation in between.

So, change max from 2 to palette.length - 1 (which will be the number of your last class, 8 in this case) to ensure the integer values in the image will line up with the palette entries.

Map.addLayer(classified, {
  min: 0,
  max: palette.length - 1,
  palette: palette
}, 'Land Use Classification');
3
  • thank you so much for the explanation, and also for clearly sharing the script. makes sense now! – rmirvine9 Mar 1 '20 at 14:45
  • Hi @rmirvine9. It appears this post answers your question. If you agree, please accept the answer by clicking the check mark below the vote tally. Accepting answers helps others know that a post is complete - thanks! – Justin Braaten Mar 1 '20 at 16:31
  • thanks, sorry I did not know to do that. – rmirvine9 Mar 1 '20 at 17:08

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.