ST_Count — 返回一个栅格给定波段的像素个数。如果没有指定波段,默认取波段1。如果参数exclude_nodata_value设置为true,那么这个函数只会统计像素值不为NODATA的像素个数。
用法
bigint ST_Count(raster rast, integer nband=1, boolean exclude_nodata_value=true); bigint ST_Count(raster rast, boolean exclude_nodata_value); bigint ST_Count(text rastertable, text rastercolumn, integer nband=1, boolean exclude_nodata_value=true); bigint ST_Count(text rastertable, text rastercolumn, boolean exclude_nodata_value);
描述
返回一个栅格给定波段的像素个数。如果没有指定波段,默认取波段1。
注意
如果参数exclude_nodata_value设置为true,那么这个函数只会统计像素值不为NODATA的像素个数。如果exclude_nodata_value值为false,那么将会统计所有的像素个数。
样例
-- example will count all pixels not 249 and one will count all pixels. SELECT rid, ST_Count(ST_SetBandNoDataValue(rast,249)) As exclude_nodata, ST_Count(ST_SetBandNoDataValue(rast,249),false) As include_nodata FROM dummy_rast WHERE rid=2; rid | exclude_nodata | include_nodata -----+----------------+---------------- 2 | 23 | 25
参考
ST_CountAgg, ST_SummaryStats, ST_SetBandNoDataValue
ST_CountAgg — 聚合函数。返回一个栅格给定波段的像素个数。 如果没有指定波段,默认取波段1。如果参数exclude_nodata_value设置为true,那么这个函数只会统计像素值不为NODATA的像素个数。
用法
bigint ST_CountAgg(raster rast, integer nband, boolean exclude_nodata_value, double precision sample_percent); bigint ST_CountAgg(raster rast, integer nband, boolean exclude_nodata_value); bigint ST_CountAgg(raster rast, boolean exclude_nodata_value);
描述
聚合函数。返回一个栅格给定波段的像素个数。如果没有指定波段,默认取波段1。 如果参数exclude_nodata_value设置为true,那么这个函数只会统计像素值不为NODATA的像素个数。如果exclude_nodata_value值为false,那么将会统计所有的像素个数。
同时会默认重采样所有的像素,想要更快获得响应,把参数sample_percent的值设置在0到1范围内。
样例
WITH foo AS ( SELECT rast.rast FROM ( SELECT ST_SetValue( ST_SetValue( ST_SetValue( ST_AddBand( ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,0) , 1, '64BF', 0, 0 ) , 1, 1, 1, -10 ) , 1, 5, 4, 0 ) , 1, 5, 5, 3.14159 ) AS rast ) AS rast FULL JOIN ( SELECT generate_series(1, 10) AS id ) AS id ON 1 = 1 ) SELECT ST_CountAgg(rast, 1, TRUE) FROM foo; st_countagg ------------- 20 (1 row)
参考
ST_Count, ST_SummaryStats, ST_SetBandNoDataValue
ST_Histogram —返回概括一个栅格或栅格覆盖数据分布的记录集。如果没有指定参数bins值,默认取autocomputed。
用法
SETOF record ST_Histogram(raster rast, integer nband=1, boolean exclude_nodata_value=true, integer bins=autocomputed, double precision[] width=NULL, boolean right=false); SETOF record ST_Histogram(raster rast, integer nband, integer bins, double precision[] width=NULL, boolean right=false); SETOF record ST_Histogram(raster rast, integer nband, boolean exclude_nodata_value, integer bins, boolean right); SETOF record ST_Histogram(raster rast, integer nband, integer bins, boolean right); SETOF record ST_Histogram(text rastertable, text rastercolumn, integer nband, integer bins, boolean right); SETOF record ST_Histogram(text rastertable, text rastercolumn, integer nband, boolean exclude_nodata_value, integer bins,boolean right); SETOF record ST_Histogram(text rastertable, text rastercolumn, integer nband=1, boolean exclude_nodata_value=true, integerbins=autocomputed, double precision[] width=NULL, boolean right=false); SETOF record ST_Histogram(text rastertable, text rastercolumn, integer nband=1, integer bins, double precision[] width=NULL,boolean right=false);
描述
返回概括一个栅格波段数据分布情况:比如像素最小值,像素最大值,像素总数,像素值占比等统计值。如果没有指定波段,nband默认取1。
注意
如果参数exclude_nodata_value设置为true,那么这个函数只会统计像素值不为NODATA的像素个数。如果exclude_nodata_value值为false,那么将会统计所有的像素个数。
width double precision[] width 一个表示每一个直方图宽度的数组。如果分隔点个数比宽度数组个数多,那么宽度数组要进行重复赋值。样例: bins=9, widths are [a, b, c] 将会输出成 [a, b, c, a, b, c, a, b, c] 。
bins integer 设置柱状图分隔数——这个值表示函数返回的记录数。如果没有指定,那么函数会取autocomputed,表示自动计算出。
right boolean 从右边而不是左边开始计算柱状图(默认)。也就是说一个区间右区间是闭区间。比如是(a, b]而不是[a, b) 。
样例 : Single raster tile - compute histograms for bands 1, 2, 3 and autocompute bins
SELECT band, (stats).* FROM (SELECT rid, band, ST_Histogram(rast, band) As stats FROM dummy_rast CROSS JOIN generate_series(1,3) As band WHERE rid=2) As foo; band| min | max | count| percent ----+-------+-------+------+--------- 1 | 249 | 250 | 2 | 0.08 1 | 250 | 251 | 2 | 0.08 1 | 251 | 252 | 1 | 0.04 1 | 252 | 253 | 2 | 0.08 1 | 253 | 254 | 18 | 0.72 2 | 78 | 113.2 | 11 | 0.44 2 | 113.2 | 148.4 | 4 | 0.16 2 | 148.4 | 183.6 | 4 | 0.16 2 | 183.6 | 218.8 | 1 | 0.04 2 | 218.8 | 254 | 5 | 0.2 3 | 62 | 100.4 | 11 | 0.44 3 | 100.4 | 138.8 | 5 | 0.2 3 | 138.8 | 177.2 | 4 | 0.16 3 | 177.2 | 215.6 | 1 | 0.04 3 | 215.6 | 254 | 4 | 0.16
样例 : Just band 2 but for 6 bins
SELECT (stats).* FROM (SELECT rid, ST_Histogram(rast, 2,6) As stats FROM dummy_rast WHERE rid=2) As foo; min | max | count | percent -----------+------------+-------+--------- 78 | 107.333333 | 9 | 0.36 107.333333 | 136.666667 | 6 | 0.24 136.666667 | 166 | 0 | 0 166 | 195.333333 | 4 | 0.16 195.333333 | 224.666667 | 1 | 0.04 224.666667 | 254 | 5 | 0.2 (6 rows) -- Same as previous but we explicitly control the pixel value range of each bin. SELECT (stats).* FROM (SELECT rid, ST_Histogram(rast, 2,6,ARRAY[0.5,1,4,100,5]) As stats FROM dummy_rast WHERE rid=2) As foo; min | max | count | percent ------+-------+-------+---------- 78 | 78.5 | 1 | 0.08 78.5 | 79.5 | 1 | 0.04 79.5 | 83.5 | 0 | 0 83.5 | 183.5 | 17 | 0.0068 183.5 | 188.5 | 0 | 0 188.5 | 254 | 6 | 0.003664 (6 rows)
参考
ST_Count, ST_SummaryStats, ST_SummaryStatsAgg
ST_Quantile — 计算一个栅格或者栅格覆盖的分位点。因此一个像素值可能是一个栅格的 25%、50%、75% 的分位点。
用法
SETOF record ST_Quantile(raster rast, integer nband=1, boolean exclude_nodata_value=true, double precision[] quantiles=NULL); SETOF record ST_Quantile(raster rast, double precision[] quantiles); SETOF record ST_Quantile(raster rast, integer nband, double precision[] quantiles); double precision ST_Quantile(raster rast, double precision quantile); double precision ST_Quantile(raster rast, boolean exclude_nodata_value, double precision quantile=NULL); double precision ST_Quantile(raster rast, integer nband, double precision quantile); double precision ST_Quantile(raster rast, integer nband, boolean exclude_nodata_value, double precision quantile); double precision ST_Quantile(raster rast, integer nband, double precision quantile); SETOF record ST_Quantile(text rastertable, text rastercolumn, integer nband=1, boolean exclude_nodata_value=true, doubleprecision[] quantiles=NULL); SETOF record ST_Quantile(text rastertable, text rastercolumn, integer nband, double precision[] quantiles);
描述
计算一个栅格或者栅格覆盖的分位点。因此一个像素值可能是一个栅格的 25%、50%、75% 的分位点。
注意
如果exclude_nodata_value值为false,那么将会统计所有的像素个数。
样例
UPDATE dummy_rast SET rast = ST_SetBandNoDataValue(rast,249) WHERE rid=2; -- Example will consider only pixels of band 1 that are not 249 and in named quantiles -- SELECT (pvq).* FROM (SELECT ST_Quantile(rast, ARRAY[0.25,0.75]) As pvq FROM dummy_rast WHERE rid=2) As foo ORDER BY (pvq).quantile; quantile | value ----------+------- 0.25 | 253 0.75 | 254 SELECT ST_Quantile(rast, 0.75) As value FROM dummy_rast WHERE rid=2; value ------ 254 --real live example. Quantile of all pixels in band 2 intersecting a geometry SELECT rid, (ST_Quantile(rast,2)).* As pvc FROM o_4_boston WHERE ST_Intersects(rast, ST_GeomFromText( 'POLYGON((224486 892151,224486 892200,224706 892200,224706 892151,224486 892151))', 26986) ) ORDER BY value, quantile,rid; rid | quantile | value -----+----------+------- 1 | 0 | 0 2 | 0 | 0 14 | 0 | 1 15 | 0 | 2 14 | 0.25 | 37 1 | 0.25 | 42 15 | 0.25 | 47 2 | 0.25 | 50 14 | 0.5 | 56 1 | 0.5 | 64 15 | 0.5 | 66 2 | 0.5 | 77 14 | 0.75 | 81 15 | 0.75 | 87 1 | 0.75 | 94 2 | 0.75 | 106 14 | 1 | 199 1 | 1 | 244 1 | 1 | 255 15 | 1 | 255
参考
ST_Count, ST_SummaryStats, ST_SummaryStatsAgg, ST_SetBandNoDataValue
ST_SummaryStats —返回一个栅格或者栅格覆盖的一个指定波段的概览统计值,包括:count(像素总数), sum(像素值之和),mean(像素平均值), stddev(像素值标准差), min(最小像素值), max(最大像素值)。如果没有指定波段,默认取波段1。
用法
summarystats ST_SummaryStats(raster rast, boolean exclude_nodata_value); summarystats ST_SummaryStats(raster rast, integer nband, boolean exclude_nodata_value); summarystats ST_SummaryStats(text rastertable, text rastercolumn, boolean exclude_nodata_value); summarystats ST_SummaryStats(text rastertable, text rastercolumn, integer nband=1, boolean exclude_nodata_value=true);
描述
返回一个栅格或者栅格覆盖的一个指定波段的概览统计值,包括:count(像素总数), sum(像素值之和), mean(像素平均值), stddev(像素值标准差), min(最小像素值), max(最大像素值)。如果没有指定波段,默认取波段1。
注意
如果参数exclude_nodata_value设置为true,那么这个函数只会统计像素值不为NODATA的像素个数。如果exclude_nodata_value值为false,那么将会统计所有的像素个数。
注意
默认会采样所有的像素,要想更快获得结果,把参数sample_percent值设置小于1。
样例 : Single raster tile
SELECT rid, band, (stats).* FROM (SELECT rid, band, ST_SummaryStats(rast, band) As stats FROM dummy_rast CROSS JOIN generate_series(1,3) As band WHERE rid=2) As foo; rid|band|count| sum | mean | stddev | min | max ---+----+-----+-------+------------+-----------+-----+----- 2 | 1 | 23 | 5821 | 253.086957 | 1.248061 | 250 | 254 2 | 2 | 25 | 3682 | 147.28 | 59.862188 | 78 | 254 2 | 3 | 25 | 3290 | 131.6 | 61.647384 | 62 | 254
样例 : Summarize pixels that intersect buildings of interest
WITH
-- our features of interest
feat AS
(SELECT gid As building_id, geom_26986 As geom FROM buildings AS b
WHERE gid IN(100, 103,150)
),
-- clip band 2 of raster tiles to boundaries of builds
-- then get stats for these clipped regions
b_stats AS
(SELECT building_id, (stats).*
FROM (SELECT building_id, ST_SummaryStats(ST_Clip(rast,2,geom)) As stats
FROM aerials.boston
INNER JOIN feat ON ST_Intersects(feat.geom,rast)
) As foo
)
-- finally summarize stats
SELECT building_id, SUM(count) As num_pixels , MIN(min) As min_pval
, MAX(max) As max_pval
, SUM(mean*count)/SUM(count) As avg_pval
FROM b_stats
WHERE count > 0
GROUP BY building_id ORDER BY building_id;
building_id | num_pixels | min_pval | max_pval |avg_pval
-------------+------------+----------+----------+------------------
100 | 1090 | 1 | 255 | 61.0697247706422
103 | 655 | 7 | 182 | 70.5038167938931
150 | 895 | 2 | 252 |185.642458100559
样例 : Raster coverage
-- stats for each band --
SELECT band, (stats).*
FROM (SELECT band, ST_SummaryStats('o_4_boston','rast', band) As stats
FROM generate_series(1,3) As band) As foo;
band |count | sum | mean |stddev | min | max
------+----------+--------+------------------+------------------+-----+-----
1 | 8450000 | 725799 | 82.7064349112426 | 45.6800222638537 |0 | 255
2 | 8450000 | 700487 | 81.4197705325444 | 44.2161184161765 |0 | 255
3 | 8450000 | 575943 | 74.682739408284 | 44.2143885481407 |0 | 255
-- For a table
-- will get better speed if set sampling to less than 100%
-- Here we set to 25% and get a much faster answer
SELECT band, (stats).*
FROM (SELECT band, ST_SummaryStats('o_4_boston','rast', band,true,0.25)
As stats
FROM generate_series(1,3) As band) As foo;
band |count | sum |mean |stddev | min| max
------+---------+--------+------------------+------------------+----+-----
1 | 2112500 | 180686 | 82.6890480473373 | 45.6961043857248 | 0 | 255
2 | 2112500 | 174571 | 81.448503668639 | 44.2252623171821 | 0 | 255
3 | 2112500 | 144364 | 74.6765884023669 | 44.2014869384578 | 0 | 255
参考
summarystats, ST_SummaryStatsAgg, ST_Count, ST_Clip
ST_SummaryStatsAgg —聚合函数。返回一个栅格或者一个栅格集合的某个指定波段的概览统计值,包括:count(像素总数),sum(像素值之和), mean(像素平均值), stddev(像素值标准差), min(最小像素值), max(最大像素值)。 如果没有指定波段,默认取波段1。
用法
summarystats ST_SummaryStatsAgg(raster rast, integer nband, boolean exclude_nodata_value, double precision sample_percent); summarystats ST_SummaryStatsAgg(raster rast, boolean exclude_nodata_value, double precision sample_percent); summarystats ST_SummaryStatsAgg(raster rast, integer nband, boolean exclude_nodata_value);
描述
聚合函数。返回一个栅格或者一个栅格集合的某个指定波段的概览统计值,包括:count(像素总数), sum(像素值之和), mean(像素平均值), stddev(像素值标准差), min(最小像素值), max(最大像素值)。 如果没有指定波段,默认取波段1。
注意
如果参数exclude_nodata_value设置为true,那么这个函数只会统计像素值不为NODATA的像素个数。如果exclude_nodata_value值为false,那么将会统计所有的像素个数。
注意
默认会采样所有的像素,要想更快获得结果,把参数sample_percent值设置小于1。
样例
WITH foo AS (
SELECT
rast.rast
FROM (
SELECT ST_SetValue(
ST_SetValue(
ST_SetValue(
ST_AddBand(
ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,0)
, 1, '64BF', 0, 0
)
, 1, 1, 1, -10
)
, 1, 5, 4, 0
)
, 1, 5, 5, 3.14159
) AS rast
) AS rast
FULL JOIN (
SELECT generate_series(1, 10) AS id
) AS id
ON 1 = 1
)
SELECT
(stats).count,
round((stats).sum::numeric, 3),
round((stats).mean::numeric, 3),
round((stats).stddev::numeric, 3),
round((stats).min::numeric, 3),
round((stats).max::numeric, 3)
FROM (
SELECT
ST_SummaryStatsAgg(rast, 1, TRUE, 1) AS stats
FROM foo
) bar;
count | round | round | round | round | round
------+---------+--------+-------+---------+-------
20 | -68.584 | -3.429 | 6.571 | -10.000 | 3.142
(1 row)
参考
summarystats, ST_SummaryStats, ST_Count, ST_Clip
ST_ValueCount — 返回一个记录集,包括像素值和指定栅格(或栅格覆盖)的指定波段的像素值在一个值集合内的像素个数。 如果没有指定波段,那么默认是波段1。默认也不统计值为NODATA的像素。像素值如果不是整数,那么像素值会进行round四舍五入处理得到一个最接近的整数值。
用法
SETOF record ST_ValueCount(raster rast, integer nband=1, boolean exclude_nodata_value=true, double precision[] searchvalues=NULL, double precision roundto=0, double precision OUT value, integer OUT count); SETOF record ST_ValueCount(raster rast, integer nband, double precision[] searchvalues, double precision roundto=0, double precision OUT value, integer OUT count); SETOF record ST_ValueCount(raster rast, double precision[] searchvalues, double precision roundto=0, double precision OUTvalue, integer OUT count); bigint ST_ValueCount(raster rast, double precision searchvalue, double precision roundto=0); bigint ST_ValueCount(raster rast, integer nband, boolean exclude_nodata_value, double precision searchvalue, double precisionroundto=0); bigint ST_ValueCount(raster rast, integer nband, double precision searchvalue, double precision roundto=0); SETOF record ST_ValueCount(text rastertable, text rastercolumn, integer nband=1, boolean exclude_nodata_value=true, double precision[] searchvalues=NULL, double precision roundto=0, double precision OUT value, integer OUT count); SETOF record ST_ValueCount(text rastertable, text rastercolumn, double precision[] searchvalues, double precision roundto=0, double precision OUT value, integer OUT count); SETOF record ST_ValueCount(text rastertable, text rastercolumn, integer nband, double precision[] searchvalues, double precision roundto=0, double precision OUT value, integer OUT count); bigint ST_ValueCount(text rastertable, text rastercolumn, integer nband, boolean exclude_nodata_value, double precision searchvalue, double precision roundto=0); bigint ST_ValueCount(text rastertable, text rastercolumn, double precision searchvalue, double precision roundto=0); bigint ST_ValueCount(text rastertable, text rastercolumn, integer nband, double precision searchvalue, double precision roundto=0);
描述
返回一个记录集,包括像素值和指定栅格(或栅格覆盖)的指定波段的像素值在一个值集合内的像素个数。 如果没有指定波段,那么默认是波段1。如果没有指定searchvalues(满足条件的要搜索的像素值),那么会返回栅格所有的像素值统计。 如果给定了searchvalue,那么会返回满足该值的所有像素的个数。
注意
如果exclude_nodata_value值为false,那么将会统计所有的像素个数。
样例
UPDATE dummy_rast SET rast = ST_SetBandNoDataValue(rast,249) WHERE rid=2;
-- Example will count only pixels of band 1 that are not 249. --
SELECT (pvc).*
FROM (SELECT ST_ValueCount(rast) As pvc
FROM dummy_rast WHERE rid=2) As foo
ORDER BY (pvc).value;
value | count
------+-------
250 | 2
251 | 1
252 | 2
253 | 6
254 | 12
-- Example will coount all pixels of band 1 including 249 --
SELECT (pvc).*
FROM (SELECT ST_ValueCount(rast,1,false) As pvc
FROM dummy_rast WHERE rid=2) As foo
ORDER BY (pvc).value;
value | count
------+-------
249 | 2
250 | 2
251 | 1
252 | 2
253 | 6
254 | 12
-- Example will count only non-nodata value pixels of band 2
SELECT (pvc).*
FROM (SELECT ST_ValueCount(rast,2) As pvc
FROM dummy_rast WHERE rid=2) As foo
ORDER BY (pvc).value;
value | count
------+-------
78 | 1
79 | 1
88 | 1
89 | 1
96 | 1
97 | 1
98 | 1
99 | 2
112 | 2
:
-- real live example.
-- Count all the pixels in an aerial raster tile band 2 intersecting a geometry
-- and return only the pixel band values that have a count > 500
SELECT (pvc).value, SUM((pvc).count) As total
FROM (SELECT ST_ValueCount(rast,2) As pvc
FROM o_4_boston
WHERE ST_Intersects(rast,
ST_GeomFromText(
'POLYGON((224486 892151,224486 892200,224706 892200,224706 892151,224486 892151))',
26986)
)
) As foo
GROUP BY (pvc).value
HAVING SUM((pvc).count) > 500
ORDER BY (pvc).value;
value | total
------+-----
51 | 502
54 | 521
-- Just return count of pixels in each raster tile
-- that have value of 100 of tiles that intersect a specific geometry --
SELECT rid, ST_ValueCount(rast,2,100) As count
FROM o_4_boston
WHERE ST_Intersects(rast,
ST_GeomFromText(
'POLYGON((224486 892151,224486 892200,224706 892200,224706 892151,224486 892151))',
26986)
) ;
rid | count
----+-------
1 | 56
2 | 95
14 | 37
15 | 64
参考
ST_Count, ST_SetBandNoDataValue
ST_AsBinary — 返回不带要SRID元数据信息的WKB描述的栅格。
用法
bytea ST_AsBinary(raster rast, boolean outasin=FALSE);
描述
返回不带要SRID元数据信息的WKB描述的栅格。如果参数outasin值为TRUE,数据库之外的波段会被当做数据库内部的波段。
对于使用binary类型游标来获取数据库之外的数据来说,使用该参数不用将数据转换成文本表述,这很有用。
注意
默认情况下,WKB输出格式包含了数据库之外的外部文件路径。如果客户端没有访问数据库之外的栅格文件权限,那么把参数outasin值设置为TRUE。
样例
SELECT ST_AsBinary(rast) As rastbin FROM dummy_rast WHERE rid=1; rastbin --------------------------------------------------------------------------------- \\001\000\000\000\000\000\000\000\000\000\000\000@\000\000\000\000\000\000\010@\000\ 000\000\000\000\000\340?\000\000\000\000\000\000\340?\000\000\000\000\000\00 0\000\000\000\000\000\000\000\000\000\000\012\000\000\000\012\000\024\000
ST_AsGDALRaster —返回指定GDAL栅格格式的栅格瓦片。栅格格式是的编译库所支持的其中一种。使用ST_GDALRasters()得到的库所支持的格式列表。
用法
bytea ST_AsGDALRaster(raster rast, text format, text[] options=NULL, integer srid=sameassource);
描述
返回指定GDAL栅格格式的栅格瓦片。函数参数意义如下:
format 输出格式控制。这是由编译的libgdal库的驱动所决定的。一般来说,支持格式有:'JPEG'、'GTIff'、'PNG'。使用函数ST_GDALDrivers得到的库所支持的格式列表。
options text型数组,GDAL参数,可选项是format参数决定的,参考GDAL Raster format options(http://www.gdal.org/frmt_various.html)。
srs 嵌入到图像中的信息,取自spatial_ref_sys 表中的 proj4text 或 srtext 字段。
样例 : JPEG Output
SELECT ST_AsGDALRaster(rast, 'JPEG') As rastjpg FROM dummy_rast WHERE rid=1; SELECT ST_AsGDALRaster(rast, 'JPEG', ARRAY['QUALITY=50']) As rastjpg FROM dummy_rast WHERE rid=2;
样例 : GTIFF Output
SELECT ST_AsGDALRaster(rast, 'GTiff') As rastjpg FROM dummy_rast WHERE rid=2; -- Out GeoTiff with jpeg compression, 90% quality SELECT ST_AsGDALRaster(rast, 'GTiff', ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'], 4269) As rasttiff FROM dummy_rast WHERE rid=2;
参考
6.3节, ST_GDALDrivers, ST_SRID
ST_AsJPEG — 返回指定波段的栅格瓦片为JPEG格式文件。如果没有指定波段,或者指定了但波段为1或超过3,那么只使用第一个波段。若指定了3个波段,那么3个波段都会使用,并且映射到RGB色彩模式中。
用法
bytea ST_AsJPEG(raster rast, text[] options=NULL); bytea ST_AsJPEG(raster rast, integer nband, integer quality); bytea ST_AsJPEG(raster rast, integer nband, text[] options=NULL); bytea ST_AsJPEG(raster rast, integer[] nbands, text[] options=NULL); bytea ST_AsJPEG(raster rast, integer[] nbands, integer quality);
描述
返回指定波段的栅格瓦片为JPEG格式文件。如果需要导出较少常用的栅格类型数据,使用函数ST_AsGDALRaster。如果没有指定波段,或者指定了但波段为1或超过3,那么只使用第一个波段。 若指定了3个波段,那么3个波段都会使用。这个函数系列有很多变体。相关参数说明如下:
nband 用于单个波段导出。
nbands 是用于导出的波段数组(注意对于JPEG格式来说,该参数值最大为3),波段的顺序是RGB。例如ARRAY[3,2,1]意味着把波段3映射成RED(红色),波段2映射成green(绿色),波段1映射成blue(蓝色)。
quality 数字从0到100,值越大,图像渲染的越好。
options GDAL中的text型数组参数,用于JPGE (参考ST_GDALDrivers函数用于创建JPEG的选项). 对于JPEG,可选项是PROGRESSIVE ON 或 OFF , QUALITY 范围是0到100,默认是75。参考 GDAL Rasterformat options(http://www.gdal.org/frmt_various.html)获取细节。
样例 : Output
-- output first 3 bands 75% quality SELECT ST_AsJPEG(rast) As rastjpg FROM dummy_rast WHERE rid=2; -- output only first band as 90% quality SELECT ST_AsJPEG(rast,1,90) As rastjpg FROM dummy_rast WHERE rid=2; -- output first 3 bands (but make band 2 Red, band 1 green, and band 3 blue, -- progressive and 90% quality SELECT ST_AsJPEG(rast,ARRAY[2,1,3],ARRAY['QUALITY=90','PROGRESSIVE=ON']) As rastjpg FROM dummy_rast WHERE rid=2;
参考
6.3节, ST_GDALDrivers, ST_AsGDALRaster, ST_AsPNG, ST_AsTIFF
ST_AsPNG —返回指定波段的栅格瓦片为PNG格式文件。如果波段中有1,3或4个波段,但没有指定波段,那么会使用所有波段。 如果栅格波段又2个或者多于4个波段,并且没有指定波段,那么只会使用1个波段。波段会被映射到RGB或RGBA模式中。
用法
bytea ST_AsPNG(raster rast, text[] options=NULL); bytea ST_AsPNG(raster rast, integer nband, integer compression); bytea ST_AsPNG(raster rast, integer nband, text[] options=NULL); bytea ST_AsPNG(raster rast, integer[] nbands, integer compression); bytea ST_AsPNG(raster rast, integer[] nbands, text[] options=NULL);
描述
返回指定栅格的波段为PNG格式文件。如果需要导出较少常用的栅格类型数据,使用函数ST_AsGDALRaster。如果没有指定波段,那么只导出前3个波段。 这个函数系列有很多变体。如果没有指定SRID,那么就会使用参数rast栅格的SRID。相关参数说明如下:
nband 用于单个波段导出
nbands 是用于导出的波段数组(注意对于PNG格式来说,该参数值最大为3),波段的顺序是RGB。例如ARRAY[3,2,1]意味着把波段3映射成RED(红色),波段2映射成green(绿色),波段1映射成blue(蓝色)。
compression 数字从1到9,值越大,压缩率越高。
options GDAL中的text型数组参数,用于PNG (参考ST_GDALDrivers函数用于创建JPEG的选项)。对于PNG,可选项是ZLEVEL(花费在压缩上的时间量-默认是6),例如ARRAY['ZLEVEL=9']。 WORLDFILE是不允许的,因为这个函数必须做两份输出。参考GDAL Raster format options获取更多细节。
样例
SELECT ST_AsPNG(rast) As rastpngFROM dummy_rast WHERE rid=2; -- export the first 3 bands and map band 3 to Red, band 1 to Green, band 2 to blue SELECT ST_AsPNG(rast, ARRAY[3,1,2]) As rastpng FROM dummy_rast WHERE rid=2;
参考
ST_AsGDALRaster, ST_ColorMap, ST_GDALDrivers, 6.3节
ST_AsTIFF —返回栅格指定波段为简单的TIFF图像文件,如果没有指定波段,那么会尝试使用所有的波段。
用法
bytea ST_AsTIFF(raster rast, text[] options=”, integer srid=sameassource); bytea ST_AsTIFF(raster rast, text compression=”,integer srid=sameassource); bytea ST_AsTIFF(raster rast, integer[] nbands, text compression=”, integer srid=sameassource); bytea ST_AsTIFF(raster rast, integer[] nbands, text[] options, integer srid=sameassource);
描述
返回栅格指定波段为简单的TIFF图像文件,如果没有指定波段,那么会尝试使用所有的波段。这个函数是ST_AsGDALRaster的包装。
如果需要导出较少常用的栅格类型数据,使用函数ST_AsGDALRaster。这个函数系列有很多变体。如果没有提供空间参考系统表srstext字段值,将会使用栅格的空间参考。相关参数说明如下:
nbands 是用于导出的波段数组(注意对于PNG格式来说,该参数值最大为3),波段的顺序是RGB。例如ARRAY[3,2,1]意味着把波段3映射成RED(红色),波段2映射成green(绿色),波段1映射成blue(蓝色)。
compression 表示压缩方式——JPEG90(默认90%,或者其他比例),LZW, JPEG, DEFLATE9。
options GDAL中的text型数组参数,用于GTiff (参考ST_GDALDrivers函数用于创建GTiff的选项). 参考GDAL Raster format options获取更多细节。
srid 空间参考系统表spatial_ref_sys中栅格的SRID值,这个用于填充地理参考信息。
样例 : Use jpeg compression 90%
SELECT ST_AsTIFF(rast, 'JPEG90') As rasttiff FROM dummy_rast WHERE rid=2;
参考
ST_GDALDrivers, ST_AsGDALRaster, ST_SRID