[postgis-users] multilinestrings - interesting function behavior

David Fawcett david.fawcett at gmail.com
Tue Nov 29 21:19:55 PST 2011


I have been playing with multilinestrings returned by using
st_intersection() on multilinestrings and polys.

My goal was to determine the length of each multilinestring and test
to determine if the segment came from the beginning or end of the
original multilinestring.

I have a solution that works using st_equals() to compare the start
and end points of the output multilinestrings with the start and end
points of the original multilinestring.

I guess if I would have RTFM'd a little more carefully, this would
have been a pretty quick exercise...  Originally, I thought that I may
be having issues with the order of the nodes in the output lines not
being preserved, but it turns out that it was due to how some
functions apply to multilinestrings.

What I learned is that st_length(), when passed a multilinestring,
will return the full length of the geometry.

But, if you pass a multilinestring to st_startpoint(), you will get
the startpoint of one of the linestring segments that makes up the
multilinestring.  (parallel results with st_endpoint())  Of course,
the manual does state that st_startpoint() takes a linestring as the
argument.  It also says that it will return a null if passes something
other than a linestring.
http://postgis.refractions.net/documentation/manual-1.4/ST_EndPoint.html

This may be obvious to the rest of you, but I thought that I would
post it here in case someone else runs into this.  I solved my problem
by using st_linemerge() on my multilinestrings before using
st_startpoint().

David.



More information about the postgis-users mailing list