제목

ST_3DClosestPoint — g2에 가장 가까운 g1 상에 있는 3차원 포인트를 반환합니다. 해당 포인트는 3D 최단 라인의 첫 번째 포인트입니다.

요약

geometry ST_3DClosestPoint(geometry g1, geometry g2);

설명

g2에 가장 가까운 g1 상에 있는 3차원 포인트를 반환합니다. 해당 포인트는 3D 최단 라인의 첫 번째 포인트입니다. 3D 최단 라인의 3D 길이가 3D 거리입니다.

This function supports 3d and will not drop the z-index.

This function supports Polyhedral surfaces.

2.0.0 버전부터 사용할 수 있습니다.

변경 사항: 2.2.0 버전부터 2D 도형 두 개를 입력할 경우, (존재하지 않는 Z을 0으로 가정하는 예전 습성 대신) 2D 포인트를 반환합니다. 2D 및 3D의 경우, 더 이상 Z가 없을 때 Z를 0으로 가정하지 않습니다.

예시

Compare the 3D closest point to the 2D closest point for a LineString and a Point.

Code
WITH input AS (
  SELECT 'POINT(100 100 30)'::geometry AS pt,
         'LINESTRING (20 80 20,98 190 1,110 180 3,50 75 1000)'::geometry AS line
)
SELECT ST_3DClosestPoint(line, pt) AS cp3d_line_pt,
       ST_ClosestPoint(line, pt) AS cp2d_line_pt
FROM input;
래스터 출력
-[ RECORD 1 ]--+--------------------------------------------------------
cp3d_line_pt   | POINT(54.69937988676193 128.93502291722837 11.547586950660556)
cp2d_line_pt   | POINT(73.07692307692307 115.38461538461539)
Figure
Geometry figure for visual-st-3dclosestpoint-01

Compare the 3D closest point to the 2D closest point for a LineString and a MultiPoint.

Code
WITH input AS (
  SELECT 'MULTIPOINT(100 100 30,50 74 1000)'::geometry AS pt,
         'LINESTRING (20 80 20,98 190 1,110 180 3,50 75 900)'::geometry AS line
)
SELECT ST_3DClosestPoint(line, pt) AS cp3d_line_pt,
       ST_ClosestPoint(line, pt) AS cp2d_line_pt
FROM input;
래스터 출력
-[ RECORD 1 ]--+--------------------------------------------------------
cp3d_line_pt   | POINT(54.69937988676193 128.93502291722837 11.547586950660556)
cp2d_line_pt   | POINT(50 75)
Figure
Geometry figure for visual-st-3dclosestpoint-02

Compare the 3D closest point to the 2D closest point for a Polygon and a MultiLineString.

Code
WITH input AS (
  SELECT ST_GeomFromEWKT(
           'POLYGON((175 150 5,20 40 5,35 45 5,50 60 5,100 100 5,175 150 5))'
         ) AS poly,
         ST_GeomFromEWKT(
           'MULTILINESTRING((175 155 2,20 40 20,50 60 -2,125 100 1,175 155 1),
                            (1 10 2,5 20 1))'
         ) AS mline
)
SELECT ST_3DClosestPoint(poly, mline) AS cp3d,
       ST_ClosestPoint(poly, mline) AS cp2d
FROM input;
래스터 출력
-[ RECORD 1 ]--+---------------------------------------
cp3d           | POINT(40.45454545454545 53.63636363636364 5)
cp2d           | POINT(20 40)
Figure
Geometry figure for visual-st-3dclosestpoint-03