Why duplicates after importing, editing, and exporting GPX?


I noticed the following issue after importing, converting, editing, and exporting GPX files: For some reason, JOSM duplicates each waypoint.

Here’s what I do:

  1. Open import.gpx
  2. In Layers, remove import.gpx
  3. Still in Layers, convert “Markers from import.gpx” to data layer (right-click) > Convert to data layer > Simplify
  4. Use lasso object to select subset of waypoints
  5. Add new layer through File
  6. Edit > Merge selection
  7. Export new layer as GPX

And here’s what I get in the output GPX:

<wpt lat="1.23" lon="4.56">
<wpt lat="1.23" lon="4.56">

What am I doing wrong?

Thank you.

Edit: I confirm duplicates are added by JOSM when importing a GPX file with waypoints and converting the “Markers from” layer into a data layer: They are not in the input file from eg. OverpassTurbo. In the process, choosing “Simplify” or “Proceed without simplifying” makes no difference.

As a work-around, the following Python script removes all empty elements, ie. that contain not even a “name” sub-element, since this is how duplicates show up in the output GPX file created in JOSM:

#pip install lxml BeautifulSoup4 pathlib

from bs4 import BeautifulSoup
import pathlib
import os
import sys

arguments = len(sys.argv) - 1
if arguments != 1:
	print ("Must pass one arg.")

print(f"**************** Handling {item}")
BASENAME = pathlib.Path(item).stem
EXTENSION = pathlib.Path(item).suffix


soup = BeautifulSoup(open(item, 'r',encoding='utf-8'), 'xml')
for wpt in soup.find_all("wpt"):
	if not wpt.find("name"):
		lat,lon = wpt.attrs.get('lat'), wpt.attrs.get('lon')
		print("No name element in ", lat,lon)

with open(OUTPUTFILE, "w",encoding='utf-8') as file: