[postgis-devel] contrib new postgis function
Emilson Ribeiro Neto
emilsonribeiro at hotmail.com
Thu Aug 22 08:07:58 PDT 2019
Dears,
After a specific demand in my work I needed to develop a function to create a single space line from two untouched geometries.
Following is code below if it is interesting to put as new functionality in postgis.
Emilson Ribeiro Neto
best regards
CREATE OR REPLACE FUNCTION public.st_mergecloselines(
geometry, geometry)
RETURNS geometry
LANGUAGE 'sql'
-- This function merge two lines that don't within (dont touching) returing a single multiline. By Emilson Ribeiro Neto
AS $BODY$
select ST_LineMerge(st_union(st_union($1,
(case
WHEN (st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2))
and (st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)))
and (st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_EndPoint($2)))
) THEN st_makeLine(ST_StartPoint($1),ST_StartPoint($2))
WHEN (st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2))
and (st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2)))
and (st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_EndPoint($2)))
) THEN st_makeLine(ST_EndPoint($1),ST_StartPoint($2))
WHEN (st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2)) < st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2))
and (st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)))
and (st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_EndPoint($2)))
) THEN st_makeLine(ST_StartPoint($1),ST_EndPoint($2))
else st_makeLine(ST_EndPoint($1),ST_EndPoint($2))
end)),$2))
$BODY$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20190822/89c475df/attachment.html>
More information about the postgis-devel
mailing list