[postgis-users] Closing polylines

Nicolas Ribot nicolas.ribot at gmail.com
Thu May 17 04:49:45 PDT 2012


The st_makeShortestLine() function used:

create or replace function st_makeShortestLine(g1 geometry, g2 geometry)
returns geometry as $$

with dist as (
select  st_distance(st_endPoint($1), st_endPoint($2)) as dee,
        st_distance(st_endPoint($1), st_startPoint($2)) as des,
        st_distance(st_startPoint($1), st_endPoint($2)) as dse,
        st_distance(st_startPoint($1), st_startPoint($2)) as dss
) select case when st_distance(st_startPoint($1), st_startPoint($2)) = 0
then st_makeline($1, st_reverse($2))
      when st_distance(st_startPoint($1), st_endPoint($2)) = 0 then
st_makeline($1, $2)
      when dee < des and dee < dse and dee < dss then st_makeline($1,
st_reverse($2))
      when des < dee and des < dse and des < dss then st_makeline($1, $2)
      when dss < dee and dss < dse and dss < des then
st_makeline(st_reverse($1), $2)
      else st_makeline($2, $1) end
from dist;
$$ language SQL;

Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120517/a8b5546d/attachment.html>


More information about the postgis-users mailing list