ST_Resize — 将栅格大小调整为新的宽度/高度
raster ST_Resize(raster rast, integer width, integer height, text algorithm=NearestNeighbor, double precision maxerr=0.125);
raster ST_Resize(raster rast, double precision percentwidth, double precision percentheight, text algorithm=NearestNeighbor, double precision maxerr=0.125);
raster ST_Resize(raster rast, text width, text height, text algorithm=NearestNeighbor, double precision maxerr=0.125);
将栅格大小调整为新的宽度/高度。 新的宽度/高度可以以精确的像素数或栅格宽度/高度的百分比来指定。 新栅格的范围将与提供的栅格的范围相同。
新的像素值是使用NearestNeighbor(英语或美式拼写)、Bilinear, Cubic, CubicSpline或 Lanczos 重采样算法计算的。 默认值是“NearestNeighbor”,它速度最快,但插值效果最差。
变体 1 期望输出栅格的实际宽度/高度。
变体 2 期望零 (0) 和一 (1) 之间的十进制值,表示输入栅格宽度/高度的百分比。
变体3可以接受输出栅格图像的实际宽度/高度,也可以接受文本百分比(例如 "20%"),表示输入栅格图像宽度/高度的百分比。
可用性:2.1.0 需要 GDAL 1.6.1+
WITH foo AS(
SELECT
1 AS rid,
ST_Resize(ST_AddBand(ST_MakeEmptyRaster(1000, 1000, 0, 0, 1, -1, 0, 0, 0),
1, '8BUI', 255, 0
),
'50%', '500') AS rast
UNION ALL
SELECT
2 AS rid,
ST_Resize(ST_AddBand(ST_MakeEmptyRaster(1000, 1000, 0, 0, 1, -1, 0, 0, 0),
1, '8BUI', 255, 0
),
500, 100) AS rast
UNION ALL
SELECT
3 AS rid,
ST_Resize(ST_AddBand(ST_MakeEmptyRaster(1000, 1000, 0, 0, 1, -1, 0, 0, 0),
1, '8BUI', 255, 0
),
0.25, 0.9) AS rast
)
SELECT
rid,
ST_Width(rast) AS width,
ST_Height(rast) AS height,
ST_ScaleX(rast) AS scale_x,
round(ST_ScaleY(rast)::numeric, 4) AS scale_y
FROM foo
ORDER BY rid
rid | width | height | scale_x | scale_y -----+-------+--------+---------+--------- 1 | 500 | 500 | 2 | -2.0000 2 | 500 | 100 | 2 | -10.0000 3 | 250 | 900 | 4 | -1.1111 (3 rows)