Skip to content

Commit 810aa02

Browse files
stephanerestani-picterrajulienr
authored andcommitted
Fix a bug in multipolygon_to_feature_collection
- This was returning an misformed MultiPolygon. Added a test to cover this function - Also fixed a hardcoded value (2) that was intended to be taken from a function argument (num_features)
1 parent 20d1ddc commit 810aa02

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/picterra/base_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def multipolygon_to_feature_collection(mp):
8686
"type": "Polygon",
8787
"coordinates": p
8888
}
89-
} for p in mp]
89+
} for p in mp["coordinates"]]
9090
}
9191

9292
T = TypeVar("T")

tests/test_client.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def add_mock_vector_layer_download_responses(layer_id, num_features):
394394
}
395395
add_mock_operations_responses("success", results=results)
396396
url = results["download_url"]
397-
mp = make_geojson_multipolygon(2)
397+
mp = make_geojson_multipolygon(num_features)
398398
responses.add(
399399
responses.GET,
400400
url,
@@ -603,6 +603,35 @@ def add_mock_folder_detector_response(folder_id: str):
603603
)
604604

605605

606+
def test_multipolygon_to_feature_collection():
607+
mp = {
608+
"type": "MultiPolygon",
609+
"coordinates": [
610+
[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
611+
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
612+
]
613+
}
614+
fc = multipolygon_to_feature_collection(mp)
615+
assert fc == {
616+
"type": "FeatureCollection",
617+
"features": [{
618+
"type": "Feature",
619+
"properties": {},
620+
"geometry": {
621+
"type": "Polygon",
622+
"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]
623+
}
624+
}, {
625+
"type": "Feature",
626+
"properties": {},
627+
"geometry": {
628+
"type": "Polygon",
629+
"coordinates": [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
630+
}
631+
}]
632+
}
633+
634+
606635
def test_detector_platform_client_base_url(monkeypatch):
607636
"""
608637
Sanity-check that the client defaults to the correct base url

0 commit comments

Comments
 (0)