Opened 8 years ago

Last modified 8 years ago

#26920 closed Cleanup/optimization

GEOSGeometry objects compare equal despite different SRID — at Initial Version

Reported by: Raphael Das Gupta Owned by: nobody
Component: GIS Version: dev
Severity: Normal Keywords: geodjango, equality
Cc: Sergey Fedoseev, Claude Paroz, jackie.leng@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Checking equality of two django.contrib.gis.geos.Point objects (and presumably any other GEOSGeometry objects of equal type) does not take the geometries' SRIDs into consideration:

from django.contrib.gis.geos import Point

p0 = Point(5, 23)  # SRID implicitly None
p1 = Point(5, 23, srid=4326)
p2 = Point(5, 23, srid=32632)

assert p0.srid != p1.srid  # passes
assert p0.srid != p2.srid  # passes
assert p1.srid != p2.srid  # passes

assert p0 != p1  # AssertionError
assert p0 != p2  # AssertionError
assert p1 != p2  # AssertionError

The semantic of coordinates depends completely on the spatial reference system. The same numbers refer to completely different positions when interpreted in different coordinate systems. Therefore, I think the geometries should compare unequal if both have an SRID set and those SRIDs are different. Not sure what should happen when comparing geometries where exactly one of them has an SRID.

If the currently observed behaviour is the intended one (or if it is retained for backwards compatibility reasons), the documentation should point that out. It already points out that the "Equality operator doesn’t check spatial equality", but to me that only made clear that spatial equality does not imply GEOSGeometry object equality, but not that neither does GEOSGeometry object equality imply spatial equality. Also, equals(), which is mentioned in that admonition as an alternative doesn't seem to care about SRID, either:

assert not p0.equals(p1)  # AssertionError
assert not p0.equals(p2)  # AssertionError
assert not p1.equals(p2)  # AssertionError

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top