-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Repository organisation -Parser correction
- Loading branch information
1 parent
2e02b48
commit f869177
Showing
26 changed files
with
370 additions
and
3,009 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
tests/dev_tests/* | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .gpx_elements import * | ||
from .gpx_parser import * | ||
from .gpx_writer import * | ||
from .gpx_writer import * | ||
from .gpx import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .gpx import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import * | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
|
||
from ..gpx_elements import Gpx | ||
from ..gpx_parser import Parser | ||
from ..gpx_writer import Writer | ||
|
||
class GPX(): | ||
""" | ||
High level GPX object. | ||
""" | ||
def __init__(self, file_path: str): | ||
self.file_path = file_path | ||
self.parser = Parser(file_path) | ||
self.gpx = self.parser.gpx | ||
self.writer = Writer() | ||
|
||
def to_string(self) -> str: | ||
return self.writer.gpx_to_string(self.gpx) | ||
|
||
def to_gpx(self, path: str): | ||
self.writer.write(self.gpx, path) | ||
|
||
def to_dataframe(self) -> pd.DataFrame: | ||
""" | ||
Convert GPX object to Pandas Dataframe. | ||
Returns: | ||
pd.DataFrame: Dataframe containing position data from GPX. | ||
""" | ||
return self.gpx.to_dataframe() | ||
|
||
def plot(self, title: str = "Track", base_color: str = "#101010", start_stop: bool = False, elevation_color: bool = False, file_path: str = None,): | ||
|
||
# Create dataframe containing data from the GPX file | ||
gpx_df = self.to_dataframe() | ||
|
||
# Visualize GPX file | ||
plt.figure(figsize=(14, 8)) | ||
if elevation_color: | ||
plt.scatter(gpx_df["longitude"], gpx_df["latitude"], c=gpx_df["elevation"]) | ||
else: | ||
plt.scatter(gpx_df["longitude"], gpx_df["latitude"], color=base_color) | ||
|
||
if start_stop: | ||
plt.scatter(gpx_df["longitude"][0], gpx_df["latitude"][0], color="#00FF00") | ||
plt.scatter(gpx_df["longitude"][len(gpx_df["longitude"])-1], gpx_df["latitude"][len(gpx_df["longitude"])-1], color="#FF0000") | ||
|
||
plt.title(title, size=20) | ||
plt.xticks([min(gpx_df["longitude"]), max(gpx_df["longitude"])]) | ||
plt.yticks([min(gpx_df["latitude"]), max(gpx_df["latitude"])]) | ||
|
||
|
||
if file_path is not None: | ||
# Check path | ||
plt.savefig(file_path) | ||
else: | ||
plt.show() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pandas as pd | ||
|
||
from .metadata import * | ||
from .track import * | ||
|
||
class Gpx(): | ||
""" | ||
Gpx (gpx) element in GPX file. | ||
""" | ||
|
||
def __init__(self, metadata: Metadata = None, tracks: list[Track] = []): | ||
self.metadata = metadata | ||
self.tracks = tracks | ||
|
||
def to_dataframe(self) -> pd.DataFrame: | ||
""" | ||
Convert Gpx element to Pandas Dataframe. | ||
Returns: | ||
pd.DataFrame: Dataframe containing position data from GPX. | ||
""" | ||
route_info = [] | ||
for track in self.tracks: | ||
for segment in track.track_segments: | ||
for point in segment.track_points: | ||
route_info.append({ | ||
"latitude": point.latitude, | ||
"longitude": point.longitude, | ||
"elevation": point.elevation | ||
}) | ||
df = pd.DataFrame(route_info) | ||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
|
||
class Metadata(): | ||
""" | ||
Metadata (metadata) element in GPX file. | ||
""" | ||
|
||
def __init__(self, link: str = "", link_text: str = "", time: str = ""): | ||
self.link = link | ||
self.link_text = link_text | ||
self.time = time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import * | ||
|
||
class TrackPoint(): | ||
""" | ||
Track point (trkpt) elevationment in GPX file. | ||
""" | ||
|
||
def __init__(self, latitude: float = None, longitude: float = None, elevation: float = None, time: str = None): | ||
self.latitude: float = latitude | ||
self.longitude: float = longitude | ||
self.elevation: float = elevation | ||
self.time: str = time | ||
|
||
|
5 changes: 4 additions & 1 deletion
5
ezGPX/gpx_elements/track_segment.py → ezgpx/gpx_elements/track_segment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
from .track_point import * | ||
|
||
class TrackSegment(): | ||
|
||
""" | ||
Track segment (trkseg) in GPX file. | ||
""" | ||
|
||
def __init__(self, track_points: list[TrackPoint] = []): | ||
self.track_points = track_points |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.