[postgis-users] Merge lines

Kevin Neufeld kneufeld at refractions.net
Wed Oct 7 08:40:25 PDT 2009


Correct.  It looks like the below query will return coincident lines along contiguous sections of 3 or more (it also 
assumes your network is properly directionalized).

This is a problem of transitive closure.  I once solved this iteratively by first finding all the degree-2 nodes in my 
network, then one node at at time, merging the two lines that share the node.

A modern approach might be to solve this using PostgreSQL's new recursive SQL syntax.
Cheers,
Kevin

Martin Fafard wrote:
> Stanley
> 
> Thank you
> But your query merge two contiguous lines but not 3 or more contiguous 
> lines...
> 
> Martin
> 
> Sufficool, Stanley a écrit :
>> Does this look correct?
>>
>> select st_linemerge(st_collect(cs1.the_geom))
>> from (
>> 	select the_geom, st_startpoint(cs_s.the_geom) as linepoint
>> 	from mylinetable cs_s
>> 	UNION ALL 
>> 	select the_geom, st_endpoint(cs_e.the_geom) as linepoint
>> 	from mylinetable cs_e
>>
>> ) as cs1
>> group by linepoint
>> having count(*) = 2
>>



More information about the postgis-users mailing list