ST_ColorMap — 從來源柵格和指定的波段建立一個最多包含四個 8BUI 波段(灰階、RGB、RGBA)的新柵格。如果未指定,則預設為波段 1。
raster ST_ColorMap(
raster rast, integer nband=1, text colormap=grayscale, text method=INTERPOLATE)
;
raster ST_ColorMap(
raster rast, text colormap, text method=INTERPOLATE)
;
將 colormap
套用至 rast
的 nband
波段,產生一個最多由四個 8BUI 波段組成的新柵格。新柵格中 8BUI 波段的數量由 colormap
中定義的顏色成分數量決定。
如果未指定 nband
,則預設為波段 1。
colormap
可以是預定義色票的關鍵字,也可以是一組定義值和顏色成分的行。
有效的預定義 colormap
關鍵字
grayscale
或 greyscale
代表一個灰階的單個 8BUI 波段柵格。
pseudocolor
代表一個顏色從藍色到綠色到紅色的四個 8BUI (RGBA) 波段柵格。
fire
代表一個顏色從黑色到紅色到淡黃色的四個 8BUI (RGBA) 波段柵格。
bluered
代表一個顏色從藍色到淡白色到紅色的四個 8BUI (RGBA) 波段柵格。
使用者可以將一組條目(每行一個)傳遞給 colormap
以指定自訂色票。每個條目通常包含五個值:像素值和對應的紅色、綠色、藍色、Alpha 成分(顏色成分介於 0 到 255 之間)。可以使用百分比值代替像素值,其中 0% 和 100% 是在柵格波段中找到的最小值和最大值。值可以用逗號(',')、製表符、冒號(':')和/或空格分隔。像素值可以設定為 nv、null 或 nodata 來表示 NODATA 值。下面提供一個範例。
5 0 0 0 255 4 100:50 55 255 1 150,100 150 255 0% 255 255 255 255 nv 0 0 0 0
colormap
的語法與 GDAL gdaldem 的 color-relief 模式相似。
method
的有效關鍵字
INTERPOLATE
使用線性內插,在給定的像素值之間平滑地混合顏色
EXACT
嚴格匹配僅在色票中找到的那些像素值。值不匹配色票條目的像素將設定為 0 0 0 0 (RGBA)
NEAREST
使用值最接近像素值的色票條目
![]() |
|
色票的一個很好的參考是 ColorBrewer。 |
![]() |
|
新柵格的結果波段將不會設定 NODATA 值。如果需要,請使用 ST_SetBandNoDataValue 設定 NODATA 值。 |
可用性:2.1.0
這是一個用來練習的垃圾表格
-- setup test raster table -- DROP TABLE IF EXISTS funky_shapes; CREATE TABLE funky_shapes(rast raster); INSERT INTO funky_shapes(rast) WITH ref AS ( SELECT ST_MakeEmptyRaster( 200, 200, 0, 200, 1, -1, 0, 0) AS rast ) SELECT ST_Union(rast) FROM ( SELECT ST_AsRaster( ST_Rotate( ST_Buffer( ST_GeomFromText('LINESTRING(0 2,50 50,150 150,125 50)'), i*2 ), pi() * i * 0.125, ST_Point(50,50) ), ref.rast, '8BUI'::text, i * 5 ) AS rast FROM ref CROSS JOIN generate_series(1, 10, 3) AS i ) AS shapes;
SELECT ST_NumBands(rast) As n_orig, ST_NumBands(ST_ColorMap(rast,1, 'greyscale')) As ngrey, ST_NumBands(ST_ColorMap(rast,1, 'pseudocolor')) As npseudo, ST_NumBands(ST_ColorMap(rast,1, 'fire')) As nfire, ST_NumBands(ST_ColorMap(rast,1, 'bluered')) As nbluered, ST_NumBands(ST_ColorMap(rast,1, ' 100% 255 0 0 80% 160 0 0 50% 130 0 0 30% 30 0 0 20% 60 0 0 0% 0 0 0 nv 255 255 255 ')) As nred FROM funky_shapes;
n_orig | ngrey | npseudo | nfire | nbluered | nred --------+-------+---------+-------+----------+------ 1 | 1 | 4 | 4 | 4 | 3
SELECT ST_AsPNG(rast) As orig_png, ST_AsPNG(ST_ColorMap(rast,1,'greyscale')) As grey_png, ST_AsPNG(ST_ColorMap(rast,1, 'pseudocolor')) As pseudo_png, ST_AsPNG(ST_ColorMap(rast,1, 'nfire')) As fire_png, ST_AsPNG(ST_ColorMap(rast,1, 'bluered')) As bluered_png, ST_AsPNG(ST_ColorMap(rast,1, ' 100% 255 0 0 80% 160 0 0 50% 130 0 0 30% 30 0 0 20% 60 0 0 0% 0 0 0 nv 255 255 255 ')) As red_png FROM funky_shapes;
![]() orig_png
|
![]() grey_png
|
![]() pseudo_png
|
![]() fire_png
|
![]() bluered_png
|
![]() red_png
|