> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ST_ClosestPoint

Returns the 2-dimensional point on geom1 that is closest to geom2. This is the first point of the shortest line between the geometries. If using 3D geometries, the Z coordinates will be ignored. If you have a 3D Geometry, you may prefer to use ST\_3DClosestPoint.
It will throw an exception indicates illegal argument if one of the params is an empty geometry.

<img src="https://mintcdn.com/wherobots/AayJA2u8CknIeTgt/images/sql-functions/ST_ClosestPoint/ST_ClosestPoint.svg?fit=max&auto=format&n=AayJA2u8CknIeTgt&q=85&s=abeb3166e562478fa444f4622a865ad5" alt="ST_ClosestPoint" width="500" height="300" data-path="images/sql-functions/ST_ClosestPoint/ST_ClosestPoint.svg" />

## Signatures

```sql theme={"system"}
ST_ClosestPoint(g1: Geometry, g2: Geometry)
```

## Parameters

<ParamField body="g1" type="Geometry" required>
  The g1 value.
</ParamField>

<ParamField body="g2" type="Geometry" required>
  The g2 value.
</ParamField>

## Return type

<ResponseField type="Geometry">
  The resulting geometry.
</ResponseField>

## Example

```sql theme={"system"}
SELECT ST_AsText( ST_ClosestPoint(g1, g2)) As ptwkt;
```

**Input:** `g1: POINT (160 40), g2: LINESTRING (10 30, 50 50, 30 110, 70 90, 180 140, 130 190)`

```
POINT(160 40)
```

**Input:** `g1: LINESTRING (10 30, 50 50, 30 110, 70 90, 180 140, 130 190), g2: POINT (160 40)`

```
POINT(125.75342465753425 115.34246575342466)
```

**Input:** `g1: 'POLYGON ((190 150, 20 10, 160 70, 190 150))', g2: ST_Buffer('POINT(80 160)', 30)`

```
POINT(131.59149149528952 101.89887534906197)
```
