<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Dears,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span lang="en"><span title="">After a specific demand in my work I needed to develop a function to create a single space line from two untouched geometries.</span><br>
<span title="">Following is code below if it is interesting to put as new functionality in postgis.</span><br>
<br>
<span title="">Emilson Ribeiro Neto</span></span><br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
best regards</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>CREATE OR REPLACE FUNCTION public.st_mergecloselines(<br>
</span>
<div>geometry, geometry)<br>
</div>
<div> RETURNS geometry<br>
</div>
<div> LANGUAGE 'sql'<br>
</div>
<div>-- This function merge two lines that don't within (dont touching) returing a single multiline. By Emilson Ribeiro Neto<br>
</div>
<div>AS $BODY$<br>
</div>
<div><br>
</div>
<div>select ST_LineMerge(st_union(st_union($1, <br>
</div>
<div>(case<br>
</div>
<div> WHEN (st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2))<br>
</div>
<div> and (st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)))<br>
</div>
<div> and (st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_EndPoint($2)))<br>
</div>
<div> ) THEN st_makeLine(ST_StartPoint($1),ST_StartPoint($2))<br>
</div>
<div> <br>
</div>
<div> WHEN (st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2))<br>
</div>
<div> and (st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2)))<br>
</div>
<div> and (st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_EndPoint($2)))<br>
</div>
<div> ) THEN st_makeLine(ST_EndPoint($1),ST_StartPoint($2)) <br>
</div>
<div> <br>
</div>
<div> WHEN (st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2)) < st_distanceSphere(ST_StartPoint($1),ST_StartPoint($2))<br>
</div>
<div> and (st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_StartPoint($2)))<br>
</div>
<div> and (st_distanceSphere(ST_StartPoint($1),ST_EndPoint($2)) < st_distanceSphere(ST_EndPoint($1),ST_EndPoint($2)))<br>
</div>
<div> ) THEN st_makeLine(ST_StartPoint($1),ST_EndPoint($2))<br>
</div>
<div> else st_makeLine(ST_EndPoint($1),ST_EndPoint($2))<br>
</div>
<div> end)),$2))<br>
</div>
<div> <br>
</div>
<span>$BODY$ </span><br>
</div>
</body>
</html>