I want to find the closest distance from one co-ordinate to the nearest end of a region. Like the image below, how can I calculate the closest distance from red dot to end of the region polygon? So basically the distance of red line.
I used ST_DISTANCE(region_polygon_1, red_dot_coordinate_1)
but it returns 0.
What would be the problem with my st_distance
function?
I used ST_DISTANCE(region_polygon_1, red_dot_coordinate_1)
to get the distance of the red line but it returns 0
Polygon includes all the internal points, so the distance from an internal point to polygon is indeed 0.
What you want is the distance to the boundary of the polygon, so what you need is
ST_DISTANCE(ST_Boundary(region_polygon_1), red_dot_coordinate_1)
If the polygon has holes, you'll need to determine whether to ignore those or find shortest distance to those - use either ST_ExteriorRing
or ST_Boundary