ST_Transform — 使用指定的重采样算法,将已知空间参考系统中的栅格重新投影到另一个已知空间参考系统。选项包括 NearestNeighbor、Bilinear、Cubic、CubicSpline、Lanczos,默认值为 NearestNeighbor。
raster ST_Transform(
raster rast, integer srid, text algorithm=NearestNeighbor, double precision maxerr=0.125, double precision scalex, double precision scaley)
;
raster ST_Transform(
raster rast, integer srid, double precision scalex, double precision scaley, text algorithm=NearestNeighbor, double precision maxerr=0.125)
;
raster ST_Transform(
raster rast, raster alignto, text algorithm=NearestNeighbor, double precision maxerr=0.125)
;
使用指定的像素变形算法,将已知空间参考系统中的栅格重新投影到另一个已知空间参考系统。如果没有指定算法,则使用“NearestNeighbor”;如果没有指定 maxerr,则使用 0.125 的 maxerror 百分比。
算法选项包括:“NearestNeighbor”、“Bilinear”、“Cubic”、“CubicSpline”和“Lanczos”。有关更多详细信息,请参阅:GDAL Warp 重采样方法。
ST_Transform 经常与 ST_SetSRID() 混淆。ST_Transform 实际上会将栅格的坐标(并对像素值进行重采样)从一个空间参考系统更改为另一个空间参考系统,而 ST_SetSRID() 只是更改栅格的 SRID 标识符。
与其他变体不同,变体 3 需要一个参考栅格作为 alignto
。转换后的栅格将被转换为参考栅格的空间参考系统 (SRID),并与参考栅格对齐 (ST_SameAlignment = TRUE)。
如果您发现转换支持无法正常工作,则可能需要将环境变量 PROJSO 设置为 PostGIS 使用的 .so 或 .dll 投影库。这只需要有该文件的文件名。例如,在 Windows 上,您可以在“控制面板”->“系统”->“环境变量”中添加一个名为 |
在转换切片的覆盖范围时,您几乎总是希望使用参考栅格来确保切片中对齐相同且没有间隙,如示例中所示:变体 3。 |
可用性:2.0.0 需要 GDAL 1.6.1+。
增强:2.1.0 添加 ST_Transform(rast, alignto) 变体。
SELECT ST_Width(mass_stm) As w_before, ST_Width(wgs_84) As w_after, ST_Height(mass_stm) As h_before, ST_Height(wgs_84) As h_after FROM ( SELECT rast As mass_stm, ST_Transform(rast,4326) As wgs_84 , ST_Transform(rast,4326, 'Bilinear') AS wgs_84_bilin FROM aerials.o_2_boston WHERE ST_Intersects(rast, ST_Transform(ST_MakeEnvelope(-71.128, 42.2392,-71.1277, 42.2397, 4326),26986) ) LIMIT 1) As foo; w_before | w_after | h_before | h_after ----------+---------+----------+--------- 200 | 228 | 200 | 170
下面显示了使用 ST_Transform(raster, srid) 和 ST_Transform(raster, alignto) 之间的差异
WITH foo AS ( SELECT 0 AS rid, ST_AddBand(ST_MakeEmptyRaster(2, 2, -500000, 600000, 100, -100, 0, 0, 2163), 1, '16BUI', 1, 0) AS rast UNION ALL SELECT 1, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499800, 600000, 100, -100, 0, 0, 2163), 1, '16BUI', 2, 0) AS rast UNION ALL SELECT 2, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499600, 600000, 100, -100, 0, 0, 2163), 1, '16BUI', 3, 0) AS rast UNION ALL SELECT 3, ST_AddBand(ST_MakeEmptyRaster(2, 2, -500000, 599800, 100, -100, 0, 0, 2163), 1, '16BUI', 10, 0) AS rast UNION ALL SELECT 4, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499800, 599800, 100, -100, 0, 0, 2163), 1, '16BUI', 20, 0) AS rast UNION ALL SELECT 5, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499600, 599800, 100, -100, 0, 0, 2163), 1, '16BUI', 30, 0) AS rast UNION ALL SELECT 6, ST_AddBand(ST_MakeEmptyRaster(2, 2, -500000, 599600, 100, -100, 0, 0, 2163), 1, '16BUI', 100, 0) AS rast UNION ALL SELECT 7, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499800, 599600, 100, -100, 0, 0, 2163), 1, '16BUI', 200, 0) AS rast UNION ALL SELECT 8, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499600, 599600, 100, -100, 0, 0, 2163), 1, '16BUI', 300, 0) AS rast ), bar AS ( SELECT ST_Transform(rast, 4269) AS alignto FROM foo LIMIT 1 ), baz AS ( SELECT rid, rast, ST_Transform(rast, 4269) AS not_aligned, ST_Transform(rast, alignto) AS aligned FROM foo CROSS JOIN bar ) SELECT ST_SameAlignment(rast) AS rast, ST_SameAlignment(not_aligned) AS not_aligned, ST_SameAlignment(aligned) AS aligned FROM baz rast | not_aligned | aligned ------+-------------+--------- t | f | t
|
|