ST_Transform() 関数は、ST_Geometry を指定された空間基準座標系に変換します。
ソースおよびターゲットの空間基準座標系の地理座標系は、同じでなければなりません。Datum 変換はサポートされません。
空間基準座標系の OGC Well-Known Text (WKT) 表記は、対応する座標系とそれらを構成する部分に関する情報を含んでいます。
ST_Transform(g ST_Geometry, SRID integer)
ST_Geometry
例 1: 空間基準座標系の仮座標原点の変更
EXECUTE FUNCTION SE_CreateSrid (110, -45, 156, -10,
"Australia: lat/lon coords");
(expression)
1002
CREATE TABLE aus_locns (name varchar(128), locn ST_Point);
INSERT INTO aus_locns VALUES ("Adelaide", '1002 point(139.14 -34.87)');
INSERT INTO aus_locns VALUES ("Brisbane", '1002 point(153.36 -27.86)');
INSERT INTO aus_locns VALUES ("Canberra", '1002 point(148.84 -35.56)');
INSERT INTO aus_locns VALUES ("Melbourne", '1002 point(145.01 -37.94)');
INSERT INTO aus_locns VALUES ("Perth", '1002 point(116.04 -32.12)');
INSERT INTO aus_locns VALUES ("Sydney", '1002 point(151.37 -33.77)');
INSERT INTO aus_locns VALUES ("Norfolk Is.", '1002 point(167.83 -29.24)');
(USE19) - Coordinates out of bounds in ST_PointIn.
INSERT INTO aus_locns VALUES ("Cocos Is.", '1002 point( 96.52 -12.08)');
(USE19) - Coordinates out of bounds in ST_PointIn.
EXECUTE FUNCTION SE_CreateSrid (95, -55, 170, -10,
"Australia + outer islands: lat/lon coords");
(expression)
1003
INSERT INTO aus_locns VALUES ("Norfolk Is.", '1003 point(167.83 -29.24)');
INSERT INTO aus_locns VALUES ("Cocos Is.", '1003 point( 96.52 -12.08)');
UPDATE aus_locns
SET locn = ST_Transform(locn, 1003)::ST_Point
WHERE ST_Srid(locn) = 1002;
例 2: 動的なデータ投影
標準的なアプリケーションでは、スペーシャル (地理空間) データは非投影緯度および経度フォーマットで格納されます。その後、地図を描くときに、特定の投影法のデータを取得します。
INSERT INTO spatial_references
(srid, description, falsex, falsey, xyunits,
falsez, zunits, falsem, munits, srtext)
VALUES (1004, "Unprojected lat/lon, NAD 83 datum",
-180, -90, 5000000, 0, 1000, 0, 1000,
SE_CreateSrtext(4269));
CREATE TABLE airports (id char(4),
name varchar(128),
locn ST_Point);
INSERT INTO airports VALUES(
'BTM', 'Bert Mooney', '1004 point(-112.4975 45.9548)');
INSERT INTO airports VALUES(
'BZN', 'Gallatin Field', '1004 point(-111.1530 45.7769)');
INSERT INTO airports VALUES(
'COD', 'Yellowstone Regional', '1004 point(-109.0238 44.5202)');
INSERT INTO airports VALUES(
'JAC', 'Jackson Hole', '1004 point(-110.7377 43.6073)');
INSERT INTO airports VALUES(
'IDA', 'Fanning Field', '1004 point(-112.0702 43.5146)');
INSERT INTO spatial_references
(srid, description, falsex, falsey, xyunits,
falsez, zunits, falsem, munits, srtext)
VALUES (1005, "UTM zone 12N, NAD 83 datum",
336000, 4760000, 1000, 0, 1000, 0, 1000,
SE_CreateSrtext(26912));
SELECT id, ST_Transform(locn, 1005) as utm FROM airports;
id BTM
utm 1005 POINT (383951.152 5090115.666)
id BZN
utm 1005 POINT (488105.331 5069271.419)
id COD
utm 1005 POINT (657049.762 4931552.365)
id JAC
utm 1005 POINT (521167.881 4828291.447)
id IDA
utm 1005 POINT (413500.979 4818519.081)
例 3: SRID が異なる形状の比較
SELECT * FROM tab1 a, tab2 b WHERE
ST_Intersects(a.shape, ST_Transform(b.shape, ST_SRID(a.shape)));