Skip to content

Commit

Permalink
Merge pull request #71 from Deltares/fix/70-layer-surface-not-calcula…
Browse files Browse the repository at this point in the history
…ted-correctly

fix(calc_library): Small correction to avoid crashing when trying to …
  • Loading branch information
Carsopre authored Jan 12, 2023
2 parents 07508ce + 6b188f7 commit bf5b8c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions koswat/core/geometries/calc_library.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import List, Union

from shapely import affinity, geometry, ops
Expand All @@ -14,6 +15,11 @@ def order_geometry_points(dike_polygon: geometry.Polygon) -> geometry.Polygon:
Returns:
geometry.Polygon: Normalized polygon.
"""
if isinstance(dike_polygon.boundary, geometry.MultiLineString):
logging.warning(
"Polygon with 'multi line', most likely due to a geometry split in two parts. Ordering of points is not supported, some calculation errors might occur as a consequence of this."
)
return dike_polygon
_x, _y = tuple(map(list, dike_polygon.boundary.coords.xy))
# remove last point as it's repeated.
_x.pop(-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def dict_to_csv_row(key, placeholders: int) -> List[str]:
]
_cost_rows.insert(0, dict_to_csv_row(_cost_per_km_key, _required_placeholders))
_csv_fom.headers = _headers
_csv_fom.entries = _location_rows + _cost_rows
_csv_fom.entries = _cost_rows + _location_rows
return _csv_fom

def _get_locations_matrix(
Expand Down
8 changes: 4 additions & 4 deletions tests/cost_report/io/csv/test_summary_matrix_csv_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def test_summary_matrix_csv_exporter_export(self, request: pytest.FixtureRequest
assert _export_path.exists()
_read_text = _export_path.read_text()
_expected_text = """;;Profile type;Kistdam;Kwelscherm;Grondmaatregel profiel;Stabiliteitswand
A;0.24;0.42;0;1;1;1
A;2.4;0.42;0;0;1;1
A;0.24;2.4;0;0;0;1
;;Cost per km (€);0.0;8144.4;16288.8;24433.2
;;Reused grass volume (volume / surface):;nan;nan;nan;nan
;;Reused grass volume (cost):;nan;nan;nan;nan
Expand All @@ -60,5 +57,8 @@ def test_summary_matrix_csv_exporter_export(self, request: pytest.FixtureRequest
;;New core layer surface (volume / surface):;nan;nan;nan;nan
;;New core layer surface (cost):;nan;nan;nan;nan
;;New maaiveld surface (volume / surface):;nan;nan;nan;nan
;;New maaiveld surface (cost):;nan;nan;nan;nan"""
;;New maaiveld surface (cost):;nan;nan;nan;nan
A;0.24;0.42;0;1;1;1
A;2.4;0.42;0;0;1;1
A;0.24;2.4;0;0;0;1"""
assert _expected_text == _read_text

0 comments on commit bf5b8c3

Please sign in to comment.