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
1.01k stars 223 forks source link

Messes with <extensions> #194

Closed Shohreh closed 4 years ago

Shohreh commented 4 years ago

Hello,

When reading tracks from an input GPX file and saving them into an output file, I notice gpxpy (1.4.0) rewrites what's in [extensions], which prevents GpsTrackEditor (a Windows application) from opening the output file.

Here's an example from the input file:

    <extensions>
      <gpxx:TrackExtension>
        <gpxx:DisplayColor>DarkGray</gpxx:DisplayColor>
      </gpxx:TrackExtension>
    </extensions>

And here's what ends up in the output file:

    <extensions>
      <http://www.garmin.com/xmlschemas/GpxExtensions/v3:TrackExtension>
        <http://www.garmin.com/xmlschemas/GpxExtensions/v3:DisplayColor>DarkGray</http://www.garmin.com/xmlschemas/GpxExtensions/v3:DisplayColor>
      </http://www.garmin.com/xmlschemas/GpxExtensions/v3:TrackExtension>
    </extensions>

Any idea why?

Thank you.

Shohreh commented 4 years ago

Is there a better solution than simply removing all [extensions] from the file created by gpxpy?

with open('input.from.gpxpy..gpx', 'r') as file:
    data = file.read()
    data = re.sub('<extensions>.+?</extensions>', '', data,flags=re.DOTALL|re.I)
f=open("input.from.gpxpy.cleaned.gpx","w")
f.write(data)
f.close()
tkrajina commented 4 years ago

This is most likely because the gpx file is missing namespaces inside <gpx ...>. I made a test in https://github.com/tkrajina/gpxpy/commit/ac394b9bc4e8a5a5f8d59ca8202041d730424024 and this works (if proper namespaces are present).

PS. If you can reproduce a bug with a test script + gpx file (with all the namespaces) -- reopen the issue.