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);
알려진 공간 참조 시스템의 래스터를 지정한 픽셀 왜곡(pixel warp) 알고리즘을 통해 또 다른 알려진 공간 참조 시스템으로 재투영합니다. 따로 알고리즘을 설정하지 않을 경우 기본값은 NearestNeighbor이며, maxerror를 설정하지 않을 경우 기본값은 백분율 0.125입니다.
알고리즘 옵션에는 'NearestNeighbor', 'Bilinear', 'Cubic', 'CubicSpline', 그리고 'Lanczos'가 있습니다. 자세한 내용은 GDAL Warp resampling methods 를 참조하십시오.
ST_Transform 함수는 종종 ST_SetSRID()와 착각당합니다. ST_Transform이 실제로 래스터의 좌표를 한 공간 참조 시스템에서 또다른 공간 참조 시스템으로 변환시키는 (그리고 픽셀 값을 리샘플링하는) 반면, ST_SetSRID()는 래스터의 SRID 식별자를 변경할 뿐입니다.
다른 변종과 달리, 변종 3은 alignto 파라미터에 참조 래스터를 요구합니다. 결과 래스터는 참조 래스터의 공간 참조 시스템(SRID)으로 변환될 것이며, (ST_SameAlignment = TRUE일 경우) 참조 래스터와 동일하게 정렬될 것입니다.
|
|
|
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 |
|
|
|
When transforming a coverage of tiles, you almost always want to use a reference raster to insure same alignment and no gaps in your tiles as demonstrated in example: Variant 3. |
2.0.0 버전부터 사용할 수 있습니다. GDAL 1.6.1 이상 버전이 필요합니다.
개선 사항: 2.1.0버전에서 ST_Transform(rast, alignto) 변종이 추가됐습니다.
Compare a source raster with nearest-neighbor and bilinear reprojections. The diagonal bands make the resampling behavior visible: nearest-neighbor keeps hard pixel steps, while bilinear smooths values between pixels. All three figures are generated from this query at manual build time.
WITH rows AS (
SELECT
y,
array_agg(
((
x * 3 + y * 5
+ CASE WHEN (x + y) % 8 < 4 THEN 80 ELSE 0 END
) % 255)::double precision
ORDER BY x
) AS row_values
FROM generate_series(1, 80) AS y
CROSS JOIN generate_series(1, 80) AS x
GROUP BY y
), source AS (
SELECT ST_SetValues(
ST_AddBand(
ST_MakeEmptyRaster(
80, 80,
-500000, 600000,
2500, -2500,
0, 0,
2163
),
1, '8BUI', 0, NULL
),
1, 1, 1,
array_agg(row_values ORDER BY y)::double precision[][]
) AS rast
FROM rows
), transformed AS (
SELECT
rast,
ST_Transform(rast, 4326, 'NearestNeighbor') AS nearest,
ST_Transform(rast, 4326, 'Bilinear') AS bilinear
FROM source
)
SELECT
ST_AsPNG(rast) AS "source (EPSG:2163)",
ST_AsPNG(nearest) AS "nearest (EPSG:4326)",
ST_AsPNG(bilinear) AS "bilinear (EPSG:4326)"
FROM transformed;
PNG image, 80 x 80 pixels | PNG image, 98 x 64 pixels | PNG image, 98 x 64 pixels
Raster reprojection and resampling.
Massachusetts State Plane source |
WGS 84 nearest-neighbor |
WGS 84 bilinear |
Variant 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_Collect(ST_ConvexHull(not_aligned) ORDER BY rid) AS not_aligned,
ST_Collect(ST_ConvexHull(aligned) ORDER BY rid) AS aligned
FROM baz
MULTIPOLYGON(((-107.007 50.2,-107.005 50.2,-107.005 50.198,-107.007 50.198,-107.007 50.2)),((-107.004 50.201,-107.002 50.201,-107.002 50.198,-107.004 50.198,-107.004 50.201)),((-107.001 50.201,-106.999 50.201,-106.999 50.198,-107.001 50.198,-107.001 50.201)),((-107.007 50.199,-107.004 50.199,-107.004 50.196,-107.007 50.196,-107.007 50.199)),((-107.004 50.199,-107.001 50.199,-107.001 50.196,-107.004 50.196,-107.004 50.199)),((-107.001 50.199,-106.999 50.199,-106.999 50.196,-107.001 50.196,-107.001 50.199)),((-107.006 50.197,-107.004 50.197,-107.004 50.194,-107.006 50.194,-107.006 50.197)),((-107.004 50.197,-107.001 50.197,-107.001 50.194,-107.004 50.194,-107.004 50.197)),((-107.001 50.197,-106.998 50.197,-106.998 50.195,-107.001 50.195,-107.001 50.197))) | MULTIPOLYGON(((-107.007 50.2,-107.005 50.2,-107.005 50.198,-107.007 50.198,-107.007 50.2)),((-107.005 50.202,-107.001 50.202,-107.001 50.198,-107.005 50.198,-107.005 50.202)),((-107.002 50.202,-106.998 50.202,-106.998 50.198,-107.002 50.198,-107.002 50.202)),((-107.007 50.199,-107.003 50.199,-107.003 50.195,-107.007 50.195,-107.007 50.199)),((-107.005 50.199,-107.001 50.199,-107.001 50.195,-107.005 50.195,-107.005 50.199)),((-107.002 50.199,-106.998 50.199,-106.998 50.195,-107.002 50.195,-107.002 50.199)),((-107.007 50.198,-107.003 50.198,-107.003 50.194,-107.007 50.194,-107.007 50.198)),((-107.005 50.198,-107.001 50.198,-107.001 50.194,-107.005 50.194,-107.005 50.198)),((-107.002 50.198,-106.998 50.198,-106.998 50.194,-107.002 50.194,-107.002 50.198)))