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

Remove waypoint while in loop? #236

Closed Shohreh closed 2 years ago

Shohreh commented 2 years ago

Hello,

I went through the test.py, but didn't find if it's possible.

I was wondering if gpxpy provides a way to remove a waypoint from the array while in a loop:

import gpxpy
import gpxpy.gpx

stations_file = open("input.gpx", mode='rt', encoding='utf-8')
stations_gpx = gpxpy.parse(stations_file)
stations_file.close()
print("Number of stations: ",len(stations_gpx.waypoints))

for waypoint in stations_gpx.waypoints:
    if waypoint.name = "Dummy":
        #How to remove waypoint from array?

Thank you.

tkrajina commented 2 years ago

stations_gpx.waypoints is a normal list. You remove an item like you remove an item from any other list. For example with filter:

>>> l = [1, 2, 3, 4, 5, 6, 7, 8]
>>> list(filter(lambda e: e % 2 == 0, l))
[2, 4, 6, 8]