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
向乐队致敬 nband
的 rast
从而产生最多由四个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 , 空 或 无数据 作为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 。
的有效关键字 method
:
INTERPOLATE
使用线性插值法在给定的像素值之间平滑地混合颜色
EXACT
以仅严格匹配在色彩映射表中找到的像素值。值与色彩映射表条目不匹配的像素将设置为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
|