[postgis-users] st_union() - a dumb question

Chris Hermansen chris.hermansen at timberline.ca
Fri Oct 26 09:27:52 PDT 2007


Kevin, thanks for the great information.

I could shamelessly pretend that I thought of actually trying it but
really wanted to hear the behaviour that is expected :-)

Kevin Neufeld wrote:
> Here are a few ways to union/merge lines together.
>
> CREATE TABLE tmp (geom geometry);
> INSERT INTO tmp VALUES ('LINESTRING(0 0, 1 0, 2 0, 5 0)'::geometry);
> INSERT INTO tmp VALUES ('LINESTRING(2 0, 5 0, 6 0, 7 0)'::geometry);
> INSERT INTO tmp VALUES ('LINESTRING(1 0, 2 0, 5 0, 6 0)'::geometry);
>
> SELECT AsText(ST_Union(geom)) FROM tmp;
>                               astext                             
> --------------------------------------------------------------------
> MULTILINESTRING((1 0,2 0),(2 0,5 0),(5 0,6 0),(6 0,7 0),(0 0,1 0))
> (1 row)
>
> SELECT AsText(ST_Collect(geom)) FROM tmp;
>                                 astext                               
> ------------------------------------------------------------------------
> MULTILINESTRING((0 0,1 0,2 0,5 0),(2 0,5 0,6 0,7 0),(1 0,2 0,5 0,6 0))
> (1 row)
>
> SELECT AsText(ST_Union(geom)) FROM (SELECT ST_Collect(geom) as geom
> FROM tmp) AS foo;
>                                 astext                               
> ------------------------------------------------------------------------
> MULTILINESTRING((0 0,1 0,2 0,5 0),(2 0,5 0,6 0,7 0),(1 0,2 0,5 0,6 0))
> (1 row)
>
> SELECT AsText(ST_Union(geom, ST_StartPoint(geom))) FROM (SELECT
> ST_Collect(geom) as geom FROM tmp) AS foo;
>                               astext                             
> --------------------------------------------------------------------
> MULTILINESTRING((0 0,1 0),(1 0,2 0),(2 0,5 0),(5 0,6 0),(6 0,7 0))
> (1 row)
>
> SELECT AsText(ST_LineMerge(geom)) FROM (SELECT ST_Union(geom) AS geom
> FROM tmp) AS foo;
>               astext               -------------------------------------
> LINESTRING(0 0,1 0,2 0,5 0,6 0,7 0)
> (1 row)
>
>
> So, to answer your question, yes, you should expect to see a
> multilinestring of 5 lines.
> If you want to sew these lines together, use LineMerge(...)
>
> Hope this helps,
>
> -------------
> Kevin Neufeld
> Software Developer
> Refractions Research Inc.
> 300-1207 Douglas St.
> Victoria, B.C., V8W 2E7
>
> Phone: (250) 383-3022
> Email: kneufeld at refractions.net
>
>
>
> Chris Hermansen wrote:
>> Good people, I have a dumb question.  Yes it's really a dumb question.
>>
>> To accompany the dumb question, I have a dumb illustration that will
>> definitely look really dumb unless viewed with a fixed-width font.
>>
>> Let's say I have three somewhat coincident lines.  Specifically, let's
>> say they're precisely colinear, and "from the side", they look like
>> this:
>>
>> A --------------------------------------
>> B         --------------------------------------------------
>> C    ----------------------------------------------
>>
>> What I'm wondering is, if I st_union() them together, should I expect as
>> a result a linestring composed of five shorter segments that looks like
>> this?  Or alternatively, maybe a bunch of short lines, or maybe a
>> multilinestring?
>>
>> U ---+----+----------------------------+----------+---------
>>
>> In other words, with "nodes" where there were endpoints of the input
>> lines?
>>
>>   
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users


-- 
Regards,

Chris Hermansen · mailto:clh at timberline.ca
tel:+1.604.714.2878 · fax:+1.604.733.0631
Timberline Natural Resource Group · http://www.timberline.ca
401 · 958 West 8th Avenue · Vancouver BC · Canada · V5Z 1E5

C'est ma façon de parler.




More information about the postgis-users mailing list