[postgis-users] How can I detect that geom != st_reverse(geom) for linestrings?

Basques, Bob (CI-StPaul) bob.basques at ci.stpaul.mn.us
Wed Sep 2 13:37:31 PDT 2015

Hi Steve,

I think you almost need to check every point from at least one linestring against the other linestring.

You could check just one end, but they could still be the same but the other end different.  Also you could have line strings with the same end points, but different intermediate points.

Your st_astext approach seems to be the most full proof, if it’s just the direction that you are looking for, then you may need to do a double (or triple condition) pass if the line strings are congruent.  You would need to check the ends against each other after finding out that they match up in physical space in order to get direction.


> On Sep 2, 2015, at 3:23 PM, Stephen Woodbridge <woodbri at swoodbridge.com> wrote:
> Hi all,
> I just noticed that it is not obvious how to determine that
> geom and st_reverse(geom) are different!
> It seems that by definition st_equals(geom, st_reverse(geom)) is true as is geom = st_reverse(geom). So this seems to be by definition, but it brings up the question how to quickly and efficiently determine that they are also different, even if they are "equal".
> I'm doing st_astext(geom) != st_astext(st_reverse(geom)) but I worry about precision issues doing this. I suppose I could also check if the st_startpoint() of the two are the same, but that seems problematic also.
> Thoughts,
>  -Steve
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

More information about the postgis-users mailing list