Google Earth Engine Export Format
The Google Earth Engine exporter creates JavaScript code snippets for use in the GEE Code Editor.
Format Details
Section titled “Format Details”| Property | Value |
|---|---|
| Identifier | gee |
| Extension | .js |
| Use case | Google Earth Engine Code Editor |
Output Formats
Section titled “Output Formats”Default Mode
Section titled “Default Mode”The default output is a JavaScript object with palette and visualization parameters:
var palettize_viz = { min: 0, max: 255, palette: ['440154', '482878', '3e4989', '31688e', '26828e', '1f9e89', '35b779', '6ece58', 'b5de2b', 'fde725']};SLD Mode
Section titled “SLD Mode”The SLD mode generates an SLD-style color map string:
var palettize_sld = '<RasterSymbolizer>' + '<ColorMap type="ramp">' + '<ColorMapEntry color="#440154" quantity="0"/>' + '<ColorMapEntry color="#21918c" quantity="127.5"/>' + '<ColorMapEntry color="#fde725" quantity="255"/>' + '</ColorMap>' + '</RasterSymbolizer>';CLI Usage
Section titled “CLI Usage”# Default mode (palette array)palettize create viridis --format gee --output viz.js --domain 0,255
# SLD modepalettize create viridis -f gee -o viz.js --domain 0,255 -O type=sld
# Custom number of colorspalettize create viridis -f gee -o viz.js --domain 0,255 --steps 10Python Usage
Section titled “Python Usage”from palettize import create_colormap, get_scaler_by_name, get_exporter
cmap = create_colormap(preset="viridis")scaler = get_scaler_by_name("linear", domain_min=0, domain_max=255)exporter = get_exporter("gee")
# Default modeoutput = exporter.export( colormap=cmap, scaler=scaler, domain_min=0, domain_max=255, options={"num_colors": 10})
# SLD modesld_output = exporter.export( colormap=cmap, scaler=scaler, domain_min=0, domain_max=255, options={"type": "sld", "num_colors": 256})Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
num_colors | int | 256 | Number of colors in palette |
type | str | "default" | Output type: "default" or "sld" |
Using in GEE Code Editor
Section titled “Using in GEE Code Editor”Visualizing an Image
Section titled “Visualizing an Image”// Paste the exported visualization parametersvar palettize_viz = { min: 0, max: 255, palette: ['440154', '482878', '3e4989', '31688e', '26828e', '1f9e89', '35b779', '6ece58', 'b5de2b', 'fde725']};
// Load your imagevar image = ee.Image('USGS/SRTMGL1_003');
// Display with the colormapMap.addLayer(image, palettize_viz, 'Elevation');Using SLD Style
Section titled “Using SLD Style”// Paste the exported SLD stringvar palettize_sld = '<RasterSymbolizer>' + '<ColorMap type="ramp">' + '<ColorMapEntry color="#440154" quantity="0"/>' + '<ColorMapEntry color="#21918c" quantity="127.5"/>' + '<ColorMapEntry color="#fde725" quantity="255"/>' + '</ColorMap>' + '</RasterSymbolizer>';
// Apply to imagevar styled = image.sldStyle(palettize_sld);Map.addLayer(styled, {}, 'Styled Elevation');Classified Data
Section titled “Classified Data”For categorical data, use exact color stops:
var landcover_viz = { min: 1, max: 5, palette: ['ff0000', '00ff00', '0000ff', 'ffff00', 'ff00ff']};
var landcover = ee.Image('MODIS/006/MCD12Q1/2019_01_01') .select('LC_Type1');Map.addLayer(landcover, landcover_viz, 'Land Cover');Color Format
Section titled “Color Format”GEE expects hex colors without the # prefix:
- Standard hex:
#440154 - GEE format:
440154
The exporter automatically strips the # prefix.
Choosing Number of Colors
Section titled “Choosing Number of Colors”- For continuous data: Use 256 colors for smooth gradients
- For display: 10-20 colors is often sufficient
- For SLD mode: More colors = larger string, slower rendering
Combining with Band Math
Section titled “Combining with Band Math”var ndvi = image.normalizedDifference(['B8', 'B4']);
var ndvi_viz = { min: -1, max: 1, palette: ['d73027', 'f46d43', 'fdae61', 'fee08b', 'd9ef8b', 'a6d96a', '66bd63', '1a9850']};
Map.addLayer(ndvi, ndvi_viz, 'NDVI');Export for Multiple Datasets
Section titled “Export for Multiple Datasets”// Temperature colormapvar temp_viz = {min: -20, max: 40, palette: ['053061', '4393c3', 'f7f7f7', 'd6604d', '67001f']};
// Precipitation colormapvar precip_viz = {min: 0, max: 500, palette: ['f7fcb9', 'addd8e', '41ab5d', '006837']};