Skip to content

Commit

Permalink
🐛 [BUG] ApidaeTrekParser now ignores when no linestring in GPX
Browse files Browse the repository at this point in the history
Previously caused a crash.
  • Loading branch information
marcantoinedupre committed Sep 3, 2024
1 parent 54c8cfe commit 7acdf81
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CHANGELOG
**Bug fixes**

- ApidaeTrekParser now fallbacks on trace filename extension if no extension property
- ApidaeTrekParser now ignores when no linestring in GPX


2.109.1 (2024-08-22)
Expand Down
2 changes: 2 additions & 0 deletions geotrek/trekking/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ def _get_geom_from_gpx(data):
geos = ApidaeTrekParser._maybe_get_linestring_from_layer(layer)
if geos:
break
else:
raise RowImportError("No LineString feature found in GPX layers tracks or routes")
geos.transform(settings.SRID)
return geos

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<gpx version="1.1" creator="GDAL 3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/1"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
</gpx>
6 changes: 6 additions & 0 deletions geotrek/trekking/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,12 @@ def test_it_handles_segment_with_single_point(self):
self.assertEqual(geom.geom_type, 'LineString')
self.assertEqual(len(geom.coords), 13)

def test_it_raises_an_error_when_no_linestring(self):
gpx = self._get_gpx_from('geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx')

with self.assertRaises(RowImportError):
ApidaeTrekParser._get_geom_from_gpx(gpx)


class KmlToGeomTests(SimpleTestCase):

Expand Down

0 comments on commit 7acdf81

Please sign in to comment.