Name

ST_Transform — 使用指定的重采样算法将已知空间参考系统中的栅格重新投影到另一个已知空间参考系统。 选项有 NearestNeighbor、Bilinear、Cubic、CubicSpline、Lanczos(默认为 NearestNeighbor)。

Synopsis

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)。

[Note]

If you find your transformation support is not working right, you may need to set the environment variable PROJSO to the projection library your PostGIS build is using. This just needs to have the name of the file. So for example on windows, you would in Control Panel -> System -> Environment Variables add a system variable called PROJSO and set it to libproj.dll. You'll have to restart your PostgreSQL service/daemon after this change.

[Warning]

在转换图块覆盖范围时,您几乎总是希望使用参考栅格来确保图块中的对齐方式相同并且没有间隙,如示例所示:变体 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
                    

原始的马萨诸塞州平面米(mass_stm)

转换为 wgs 84 经纬度 (wgs_84) 后

使用双线性算法而不是 NN 默认值 (wgs_84_bilin) 转换为 wgs 84 经纬度后

示例:变体3

下面展示了使用 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
                

未对齐

对齐

相关信息

ST_Transform, ST_SetSRID