tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
993 stars 223 forks source link

Equality test for GPX class #158

Closed gucharbon closed 4 years ago

gucharbon commented 5 years ago

This is not a bug

I'm using gpxpy==1.3.4 with Python 3.6.1 in Jupyter Notebook.

I use gpxpy to load data from GPX files.

I wanted to compare two GPX objects to see if they were equal, but I found out that creating two GPX objects from same file result in False when testing equality:

g1 = load_gpx("./data/demo.gpx") g2 = load_gpx("./data/demo.gpx")

g1 == g2 => False

In order to compare two objects I use g1.to_xml() == g2.to_xml()

I tried to search in issues, but I did not found one related to equality. Could two gpx objects be different if they generate an identitcal string using .to_xml() method ? If no, what are the reasons for not overriding the default equality test ?

Thanks for your work anyways !

tkrajina commented 4 years ago

The problem here is that -- it's complicated. Especially now with extensions. I mean, when exactly do you consider two GPX tracks to be identical? Let's say both have the same tracks, segments, points, waypoints and routes. But one has an additional extension. Are they equal tracks -- yes. Are they equal gpx objects. Nope. What if extensions contain the same objects but extension prefixes are different? And so on...

Consider also that, in order to check equality (with extensions) -- you need to not only check all the usual object fields, but also traverse the extension(s) DOM elements. And that will be slow.

So, my suggestion -- you decide what equals(gpx1, gpx2) means for you. And implement it.

What I'd be interested in merging is an algorithm which finds if gpx1 and gpx2 are similar (even when not having the same points). For example, if two different GPX devices record the same track. But that's another story.