[postgis-users] linestring aggregation

Arnaud Lesauvage arnaud.listes at codata.eu
Wed Dec 30 06:20:13 PST 2009


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





More information about the postgis-users mailing list