I have 3 geometries
- 1 polygon
- 1 point on boundary
- 1 multilinestring
In this image you can see the problem. I need to find shortest line from point (green square) to line (red), but the line must be inside polygon. The green line is the solution, but ST_shortestLine or ST_ClosestPoint give me the pink line, and this line is not within polygon
This is my SQL:
SELECT ST_AsText(st_shortestLine(line.geom,point.geom)) FROM (SELECT st_geomFromText('POINT(3 5)') AS geom) AS point, (SELECT st_geomFromText('MULTILINESTRING ((1 3,11 3,11 9,1 9))') geom) AS line, (SELECT st_geomFromText('POLYGON ((0 5,10 5, 10 4,0 4,0 2,12 2,12 13, 0 13, 0 5))') geom) polygon WHERE ST_Within( st_shortestLine(line.geom,point.geom), polygon.geom )
Without WHERE condition return the bad line, and with WHERE condition give me a null value.