[postgis-users] [SOLVED]: linestring aggregation

Nicolas Gillet - MARKET-IP nicolas.gillet at market-ip.com
Wed Dec 30 08:41:38 PST 2009


Hello,

Thank you very much this works fine.

You taught me two major things I didn't know.
First I had re-invented the wheel with my geometry_sum function with was
plainly what st_collect did in a much faster way.
Second, I had never use ST_linemerge which does a true merge of line
strings, not simply making a multilinstring of them.

I was afraid that adding all the lines and then split them would take a huge
lot of time but actually it was very fast !

With your tips I have strongly improved my treatments.

Thank you very much 

Nicolas.

-----Message d'origine-----
De : postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] De la part de Arnaud
Lesauvage
Envoyé : mercredi 30 décembre 2009 15:20
À : postgis-users at postgis.refractions.net
Objet : Re: [postgis-users] linestring aggregation

Le 29/12/2009 11:39, Nicolas Gillet - MARKET-IP a écrit :
> I am trying to aggregate linestrings together based on their attributes
and
> the fact that they are touching each other.
>
> Therefore I found out how to write a very basic aggregate function :
>
>     CREATE AGGREGATE geometry_sum (
>                  SFUNC = st_union,
>                  BASETYPE = geometry,
>                  STYPE = geometry);


Nicolas, what does your geometry_sum function do precisely ?
There is a ST_Linemerge function that takes a collection of linestrings 
as an argument and merges them together into a multilinestring.
Maybe it doesn't give you the result you expect ?

With a table "thetable" having an "attrib" field and a "geom" field, I 
would write the query like this :

SELECT attrib, (st_dump(merged_geom)).geom
FROM (
	SELECT attrib, ST_Linemerge(ST_Collect(geom)) AS merged_geom
	FROM thetable
	GROUP BY attrib
) AS subq;

Does this solve your problem ?


Regards,
Arnaud


_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list