This topic describes the ST_3DClosestPoint function. This function returns the 3D point that is the closest from one geometry object to another geometry object. This point is also the first point on the line that represents the shortest straight distance between the geometry objects.

Syntax

geometry  ST_3DClosestPoint(geometry  g1 , geometry  g2);

Parameters

Parameter Description
g1 The first geometry object that you want to specify.
g2 The second geometry object that you want to specify.

Description

  • This function supports 3D objects and does not delete z coordinates.

    If you specify 3D objects, this function calculates the shortest 3D distance between the objects.

  • This function supports polyhedral surfaces.
  • If you specify 2D objects, this function returns a 2D point that does not have a z coordinate.

Examples

Find the 3D point that is the closest from one geometry object to another geometry object by using the default parameter settings.
SELECT ST_AsText(ST_3DClosestPoint('LINESTRING(0 0 0,1 1 1)'::geometry,'LINESTRING(0 0 1,1 1 0)'::geometry));
       st_astext
-----------------------
 POINT Z (0.5 0.5 0.5)
(1 row)