[postgis-users] getting the longest connected path of a multistring

arno arno at renevier.net
Thu Dec 16 05:28:32 PST 2010


Hi,
I have a multistring geometry, and I want to get the maximal length of
consecutive linestrings.

For example, if the following example is my multilinestring, I want to get the 
length of A + B + E



\ A
 \                    C
  \         B          /
   -------------------
 /                    \
  D                    \
                        \  E
                         \
    \ F                   \
     \   G
      \___

So, I think I should try to generate all the possible paths and check their
length and get the maximum of them.
I've looked at ST_LineMerge but, from what I understand, it will take the first
segment, and add them as soon as it can. So, I think I'll end up with (ABC, D,
E, FG). Am I right about that ?

So, I've tried to decompose the geom in an array of linestring (with
ST_NumGeometries and ST_GeometryN), then rearrange them with a permutation
(http://wiki.postgresql.org/wiki/Permutations). But this quickly became
complicated, so before going on in that direction, I was wondering if there was
an easy/direct way of doing what I want.

thanks
arno



More information about the postgis-users mailing list