Python command-line tool for extracting geographic and elevation data from GPX files into structured TXT output.
The project parses GPX/XML files, extracts waypoint information and converts the data into a tab-separated text format that can be reused in other workflows or data-processing tools.
- Python
- XML
- GPX
xml.etree.ElementTreeargparse- Regular expressions
pathlib- Command-line interfaces
No external Python dependencies are required.
- Process a single GPX file
- Process multiple GPX files from a directory
- Extract waypoint coordinates
- Extract elevation data
- Extract waypoint names and descriptions
- Extract distance and angle information from GPX descriptions
- Automatically detect the GPX XML namespace
- Generate one structured TXT file for each GPX input
- Automatically create the output directory
- Support custom input and output paths
- Preserve UTF-8 text output
Each waypoint can generate the following fields:
type
latitude
longitude
altitude (m)
distance (km)
name
desc
angle
The output uses tab-separated values, making it easy to inspect or import into other tools.
gpx-data-extractor/
├── examples/
│ ├── input/
│ │ └── linha_0.gpx
│ └── output/
│ └── linha_0.txt
│
├── .gitignore
├── gpx_extractor.py
└── README.md
- Python 3
The project uses only modules from the Python standard library, so no additional packages need to be installed.
To process all .gpx files inside a directory:
python gpx_extractor.py --input examples/input --output examples/outputThe script searches the specified input directory for GPX files and creates one TXT file for each input file.
For example:
examples/input/linha_0.gpx
generates:
examples/output/linha_0.txt
You can also process only one file:
python gpx_extractor.py \
--input examples/input/linha_0.gpx \
--output examples/output| Argument | Required | Description |
|---|---|---|
--input |
Yes | Path to a GPX file or directory containing GPX files |
--output |
No | Directory where TXT files will be generated |
If --output is omitted, the default directory is:
output/
The generated file starts with:
type latitude longitude altitude (m) distance (km) name desc angle
Each GPX waypoint is then written as a new row.
Conceptually:
W -16.0000 -48.0000 950 0 Point 1 Waypoint description 90
W -16.0001 -48.0002 955 0.25 Point 2 Waypoint description 110
The exact values depend on the contents of the GPX file.
The processing flow is:
GPX file
│
▼
XML parsing
│
├── Detect GPX namespace
│
▼
Find waypoints
│
├── latitude
├── longitude
├── elevation
├── name
└── description
│
▼
Extract distance and angle
│
▼
Create structured waypoint data
│
▼
Write TXT output
The application uses Python's built-in:
xml.etree.ElementTreeto parse GPX files.
Instead of depending on a fixed GPX namespace, the script detects the namespace from the XML root element.
This makes the parser less dependent on one specific GPX file structure.
Some GPX generators store additional information such as distance and angle inside HTML-formatted waypoint descriptions.
The script analyzes <td> elements in the description and searches for fields labeled:
Distance
Angle
If explicit labels are not found, the script also includes a fallback strategy based on the position of the values in the description.
When the input is a directory:
python gpx_extractor.py --input routesthe application searches for:
*.gpx
and processes the files in sorted order.
When the input is a single file, the program validates that it has the .gpx extension before processing it.
Output filenames are automatically derived from the input filename.
For example:
route_01.gpx
becomes:
route_01.txt
This means the application does not depend on a specific filename convention.
The application stops with a clear message when:
- the input path does not exist;
- a single input file does not have the
.gpxextension; - no GPX files are found in the selected directory.
Examples:
Input path not found: routes
The input file must have a .gpx extension.
No GPX files found.
The repository includes a sample GPX file:
examples/input/linha_0.gpx
and the corresponding generated output:
examples/output/linha_0.txt
This allows the extraction workflow to be tested without needing an external dataset.
This project demonstrates practical knowledge of:
- Python scripting
- XML parsing
- GPX file processing
- geospatial data extraction
- command-line interfaces
- file and directory manipulation
- regular expressions
- structured data transformation
- batch file processing
- input validation
- separation of processing responsibilities
Future versions could include:
- CSV output
- JSON output
- support for GPX tracks and routes in addition to waypoints
- command-line selection of output format
- automatic unit conversion
- elevation statistics
- total route distance calculation
- GeoJSON export
- automated tests
- logging
- packaging as an installable Python CLI
- visualization of extracted points on a map
Daniel Martínez Alencar Freitas
GitHub: DanielMartinez2