[postgis-users] st_collect returning more geometries than I want

Stephen Woodbridge woodbri at swoodbridge.com
Tue Jan 3 06:49:40 PST 2012


On 1/3/2012 9:19 AM, Richard Greenwood wrote:
> This seems so simple that I'm embarrassed to ask, but, putting my
> pride in my pocket...
>
> I want to aggregate two linestrings into one. The endpoint of the
> first linestring is coincident with the start point of the second.
> Using st_collect() or st_union() I get a multiLineString with 2
> geometries. How can I get a single linestring, or a multiLineString
> with just 1 geometry?
>
> I cases where I aggregate linestrings that do not have coincident
> start/end points I do want multiLineStrings with multiple geometries.
>
> I tried the st_dump() "trick" with no better luck:
>
>    SELECT label, st_numgeometries(ST_Collect (f.the_geom ))
>    FROM ( SELECT label, (ST_Dump (wkb_geometry )).geom As the_geom
>        from road_cl
>      ) As f
>    GROUP BY label
>
> Basically I'm looking for the opposite of st_multi()
>
> Thanks,
> Rich
>

Hi Rich,

I think you are looking for:

http://postgis.refractions.net/docs/ST_LineMerge.html

-Steve



More information about the postgis-users mailing list