GIS Workflows
This guide demonstrates common GIS workflows using Palettize to create colormaps for desktop GIS, web services, and raster processing.
GDAL Raster Coloring
Section titled “GDAL Raster Coloring”Colorize a DEM
Section titled “Colorize a DEM”# Create a terrain colormappalettize create --colors "darkgreen,yellow,brown,white" \ --format gdal --output terrain.txt --domain 0,4000 --steps 256
# Apply with gdaldemgdaldem color-relief dem.tif terrain.txt colored_dem.tifColorize NDVI
Section titled “Colorize NDVI”# Red-yellow-green for vegetationpalettize create --colors "#8B0000,#FFD700,#228B22" \ --format gdal --output ndvi.txt --domain -1,1 --steps 256
gdaldem color-relief ndvi.tif ndvi.txt colored_ndvi.tifTemperature Anomalies
Section titled “Temperature Anomalies”# Diverging colormap for anomaliespalettize create RdBu --format gdal --output temp.txt \ --domain -10,10 --steps 256
gdaldem color-relief temp_anomaly.tif temp.txt colored_temp.tifQGIS Styling
Section titled “QGIS Styling”Create and Import Style
Section titled “Create and Import Style”# Export viridis for QGISpalettize create viridis --format qgis --output viridis.xml \ --domain 0,255 --steps 11In QGIS:
- Settings > Style Manager > Import
- Select
viridis.xml - Apply to your raster layer
Pseudocolor Raster
Section titled “Pseudocolor Raster”# Create a colormap for elevation datapalettize create terrain --format qgis --output elevation.xml \ --domain 0,3000 -O ramp_type=gradient --steps 20Classified Raster
Section titled “Classified Raster”# Discrete classespalettize create viridis --format qgis --output classes.xml \ --domain 0,5 -O ramp_type=exact --steps 6GeoServer SLD Styling
Section titled “GeoServer SLD Styling”Raster Layer Style
Section titled “Raster Layer Style”# Create SLD for a raster layerpalettize create viridis --format sld --output elevation.sld \ --domain 0,1000 -O layer_name=dem -O style_name=elevation_viridis
# Upload to GeoServercurl -u admin:geoserver -XPOST \ -H "Content-Type: application/vnd.ogc.sld+xml" \ -d @elevation.sld \ "http://localhost:8080/geoserver/rest/styles"Polygon Thematic Map
Section titled “Polygon Thematic Map”# SLD for polygon datapalettize create YlOrRd --format sld --output population.sld \ --domain 0,1000000 -O geometry_type=polygon \ -O layer_name=counties -O style_name=population_density \ --scale logComplete Workflow: Elevation Mapping
Section titled “Complete Workflow: Elevation Mapping”1. Prepare Colormap
Section titled “1. Prepare Colormap”# Create a terrain colormap with multiple formatspalettize create --colors "darkblue,lightblue,green,yellow,orange,brown,white" \ --format gdal,qgis,sld \ --output "elevation_{format}.{ext}" \ --domain -100,4000 \ --steps 256 \ --name "Elevation"2. Process with GDAL
Section titled “2. Process with GDAL”# Apply to DEMgdaldem color-relief input_dem.tif elevation_gdal.txt output_colored.tif \ -of GTiff -co COMPRESS=LZW -co TILED=YES3. Import to QGIS
Section titled “3. Import to QGIS”# QGIS Python Consolefrom qgis.core import QgsRasterLayer, QgsProject
layer = QgsRasterLayer("output_colored.tif", "Elevation")QgsProject.instance().addMapLayer(layer)4. Publish to GeoServer
Section titled “4. Publish to GeoServer”# Upload stylecurl -u admin:geoserver -XPOST \ -H "Content-Type: application/vnd.ogc.sld+xml" \ -d @elevation_sld.sld \ "http://localhost:8080/geoserver/rest/styles"
# Apply to layercurl -u admin:geoserver -XPUT \ -H "Content-Type: text/xml" \ -d "<layer><defaultStyle><name>Elevation</name></defaultStyle></layer>" \ "http://localhost:8080/geoserver/rest/layers/workspace:dem_layer"Python Integration
Section titled “Python Integration”Batch Process Multiple DEMs
Section titled “Batch Process Multiple DEMs”import subprocessfrom pathlib import Pathfrom palettize import create_colormap, get_scaler_by_name, get_exporter
# Create colormapcmap = create_colormap( colors=["darkgreen", "yellow", "brown", "white"], name="Terrain")scaler = get_scaler_by_name("linear", domain_min=0, domain_max=4000)exporter = get_exporter("gdal")
# Exportcolor_file = Path("terrain.txt")color_file.write_text( exporter.export(cmap, scaler, 0, 4000, {"num_colors": 256}))
# Process multiple DEMsdem_files = Path("dems").glob("*.tif")for dem in dem_files: output = Path("colored") / f"{dem.stem}_colored.tif" subprocess.run([ "gdaldem", "color-relief", str(dem), str(color_file), str(output), "-of", "GTiff", "-co", "COMPRESS=LZW" ])Dynamic Color Assignment
Section titled “Dynamic Color Assignment”from palettize import create_colormap, get_scaler_by_nameimport rasterioimport numpy as np
# Load raster to get value rangewith rasterio.open("data.tif") as src: data = src.read(1) valid = data[data != src.nodata] vmin, vmax = np.percentile(valid, [2, 98])
# Create colormap for actual data rangecmap = create_colormap(preset="viridis")scaler = get_scaler_by_name("linear", domain_min=vmin, domain_max=vmax)
# Generate colors for visualizationcolors = []for val in np.linspace(vmin, vmax, 10): colors.append(cmap.apply_scaler(val, scaler))print(colors)Tips for GIS Workflows
Section titled “Tips for GIS Workflows”Choosing Color Counts
Section titled “Choosing Color Counts”| Use Case | Recommended Steps |
|---|---|
| GDAL color-relief | 256 (smooth gradient) |
| QGIS pseudocolor | 10-20 (discrete classes) |
| SLD ramp | 256 (continuous) |
| SLD intervals | 5-10 (classified) |
| Print maps | 7-11 (readable legend) |
Data Domain Selection
Section titled “Data Domain Selection”# Check actual data range firstgdalinfo -mm your_raster.tif
# Use percentiles to avoid outlierspalettize create viridis -f gdal -o output.txt --domain 10,990Handling NoData
Section titled “Handling NoData”# GDAL with NoDatapalettize create viridis -f gdal -o output.txt \ --domain 0,255 -O nodata_value=nv -O "nodata_color=0,0,0,0"Scaling for Skewed Data
Section titled “Scaling for Skewed Data”# Log scale for population densitypalettize create YlOrRd -f gdal -o pop.txt \ --domain 1,100000 --scale log
# Sqrt scale for count datapalettize create viridis -f gdal -o counts.txt \ --domain 0,10000 --scale sqrt