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

Stephen Woodbridge woodbri at swoodbridge.com
Wed Sep 2 14:04:38 PDT 2015

Hi Bob,

Yes, for now I'm just taking a pgrouting path and reversing some of the 
edges so the coordinates flow correctly from end to end of the path. But 
it just dawned on me that I can change the test to
geom::text = st_reverse(geom)::text and this will avoid the precision 
issue I was worded about.

It just seems like we should have a function that allows us to check for 

create or replace st_isSameGeometry(a geometry, b geometry)
returns boolean
language sql
select a::text=b::text;


On 9/2/2015 4:37 PM, Basques, Bob (CI-StPaul) wrote:
> 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.
> bobb
>> 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
> _______________________________________________ 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