Skip to content

Commit

Permalink
fix and test for length of multilinesegment
Browse files Browse the repository at this point in the history
  • Loading branch information
elbeejay committed Jun 15, 2024
1 parent 19d2dbe commit 724c012
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/GOSTnets/osm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def line_length(line, ellipsoid="WGS-84"):
"""
if line.geometryType() == "MultiLineString":
return sum(line_length(segment) for segment in line)
return sum(line_length(segment) for segment in line.geoms)

return sum(
distance.geodesic(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_osm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import mock
import geopandas as gpd
from shapely.geometry import LineString
from shapely.geometry import MultiLineString
import os


Expand Down Expand Up @@ -119,3 +120,10 @@ def test_line_length():
# check the result
assert isinstance(result, float)
assert result > 0
# make a multilinestring
mline = MultiLineString([[[0, 0], [1, 2]], [[4, 4], [5, 6]]])
# run the function
mresult = osm_parser.line_length(mline)
# check the result
assert isinstance(mresult, float)
assert mresult > 0

0 comments on commit 724c012

Please sign in to comment.