Skip to content

Commit

Permalink
🐛 [BUG] Apidae Trek parser 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 2, 2024
1 parent d1ec3e9 commit f244a3e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
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 @@ -1480,6 +1480,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 f244a3e

Please sign in to comment.