Skip to content

Commit

Permalink
#1 #3 Work in progress:
Browse files Browse the repository at this point in the history
-Update documentation
-Add first test for GPX.folium_plot method (not working)

[ci skip]
  • Loading branch information
FABallemand committed Sep 16, 2023
1 parent dff6cb2 commit 94ec4de
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 9 deletions.
4 changes: 4 additions & 0 deletions doc/ezgpx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Subpackages
ezgpx.gpx_elements
ezgpx.gpx_parser
ezgpx.gpx_writer
ezgpx.kml_parser
ezgpx.kml_writer
ezgpx.parser
ezgpx.writer
ezgpx.utils

Module contents
Expand Down
22 changes: 21 additions & 1 deletion doc/tutorials/parsing.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Parsing
-------

GPX Files
^^^^^^^^^

In order to parse a GPX file, simply create a new :py:class:`~ezgpx.gpx.GPX` object with the path to the file.

.. note::
Expand All @@ -12,4 +15,21 @@ In order to parse a GPX file, simply create a new :py:class:`~ezgpx.gpx.GPX` obj
from ezGPX import GPX

# Parse GPX file
gpx = GPX("file.gpx")
gpx = GPX("file.gpx")


KML Files
^^^^^^^^^

In order to parse a KML file, simply create a new :py:class:`~ezgpx.gpx.GPX` object with the path to the file.

.. note::

This method is mainly designed to perform a simple conversion from KML to GPX. To that extent, only GPS data from the KML files will be processed.

::

from ezGPX import GPX

# Parse KML file
gpx = GPX("file.kml")
4 changes: 3 additions & 1 deletion ezgpx/gpx/gpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ def folium_plot(
# Plot track points
gpx_df = self.to_dataframe()
gpx_df["coordinates"] = list(
zip(gpx_df.latitude, gpx_df.longitude))
zip(gpx_df.lat, gpx_df.lon))
folium.PolyLine(gpx_df["coordinates"],
tooltip=self.name(), color=color).add_to(m)

Expand Down Expand Up @@ -1183,6 +1183,8 @@ def folium_plot(
).add_to(m)

# Save map
if file_path is None:
file_path = "unnamed.html"
m.save(file_path)

# Open map in web browser
Expand Down
38 changes: 31 additions & 7 deletions tests/test_GPX.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,7 @@ def _test_matplotlib_plot_4(self):
return np.array_equal(test_img, ref_img)

@pytest.mark.skip(reason="not ready")
def test_matplotlib_plot(self, remove_tmp: bool = True):
"""
Test matplotlib_plot method.
Args:
remove_tmp (bool, optional): Remove temporary folder. Defaults to True.
"""
def test_matplotlib_plot(self):
# Parse GPX file
self.gpx = GPX(os.path.join(FILES_DIRECTORY, "strava_run_1.gpx"))
# Tests
Expand All @@ -323,6 +317,36 @@ def test_matplotlib_plot(self, remove_tmp: bool = True):
# self._test_matplotlib_plot_3()
# self._test_matplotlib_plot_4()

def _test_folium_plot_1(self):
# Plot
self.gpx.folium_plot(tiles="openStreetMap",
color="#110000",
start_stop_colors=None,
way_points_color=None,
minimap=False,
coord_popup=False,
title=None,
zoom=12,
file_path="tmp/folium_strava_run_1.html",
open=False)
# Compare files
return filecmp.cmp("tmp/folium_strava_run_1.html", os.path.join(REFERENCE_FILES_DIRECTORY, "folium_strava_run_1.html"), False)

@pytest.mark.skip(reason="not ready")
def test_folium_plot(self):
self.test_init() # For developping purpose only (using: pytest test_GPX.py::TestGPX::test_folium_plot)
# Parse GPX file
self.gpx = GPX(os.path.join(FILES_DIRECTORY, "strava_run_1.gpx"))
# Tests
assert(self._test_folium_plot_1())
# assert(self._test_folium_plot_2())
# assert(self._test_folium_plot_3())
# assert(self._test_folium_plot_4())
# self._test_folium_plot_1()
# self._test_folium_plot_2()à
# self._test_folium_plot_3()
# self._test_folium_plot_4()

#==== Destroy ============================================================#

def test_destroy(self, remove_tmp: bool = True):
Expand Down
83 changes: 83 additions & 0 deletions tests/test_files/reference_files/folium_strava_run_1.html

Large diffs are not rendered by default.

0 comments on commit 94ec4de

Please sign in to comment.