# Distance between a point and polygon

What is the meaning of distance between a point and polygon while using ST_Distance? I'm aware that it means the shortest distance between them but what is here meant by shortest distance?

• ST_Length(ST_ShortestLine(a,b) = ST_Distance(a,b) – ziggy Dec 29 '17 at 16:24

It means the distance between a Point and the closest part of a Polygon's boundary (i.e. its vertices and edges, essencially its perimetre). Ex:

``````select st_distance(
st_geomfromtext('POINT (0 0)'),
st_geomfromtext('POLYGON ((1 1, 2 1, 2 2, 1 2, 1 1))')
)
``````

This returns 1.414213, which is the expected value between the point in (0, 0) and the closest part of the polygon at (1, 1). Another example, with an edge this time:

``````select st_distance(
st_geomfromtext('POINT (0 0)'),
st_geomfromtext('POLYGON ((1 1, 2 1, 2 -1, 1 -1, 1 1))')
)
``````

This returns 1. Finally, if your point intersects the polygon anywhere, the distance will be zero:

``````select st_distance(
st_geomfromtext('POINT (0 0)'),
st_geomfromtext('POLYGON ((1 1, 1 -1, -1 -1, -1 1, 1 1))')
)
``````
• If it was helpful, consider accepting the answer, so your post is flagged as answered :) – Roberto Ribeiro Dec 31 '17 at 10:18

For geometry type returns the minimum 2D Cartesian distance between two geometries in projected units (spatial ref units). For geography type defaults to return the minimum geodesic distance between two geographies in meters.

Definition extracted from: https://postgis.net/docs/ST_Distance.html