From c5d3816971c0984815933b962bb3f44100d34ac7 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 9 Nov 2022 11:51:03 +0000 Subject: [PATCH] jsontogeojson: add any_spans_with_geometry and any_nodes_with_geometry to meta Helpful for https://github.com/Open-Telecoms-Data/cove-ofds/issues/6 --- CHANGELOG.md | 2 ++ libcoveofds/geojson.py | 7 +++++++ tests/fixtures/json_to_geojson/basic_1.expected.meta.json | 4 +++- .../json_to_geojson/no_geometry_1.expected.meta.json | 4 +++- .../json_to_geojson/organisations_1.expected.meta.json | 4 +++- tests/fixtures/json_to_geojson/phases_1.expected.meta.json | 4 +++- 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e22b976..b8d8beb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add more fields to output object - GeoJSON to JSON: - meta information includes inconsistent ids on organisations and phases +- JSON to GeoJSON: + - add any_spans_with_geometry and any_nodes_with_geometry to meta - Python Validate: - add more information to errors diff --git a/libcoveofds/geojson.py b/libcoveofds/geojson.py index f29a200..e9bcee3 100644 --- a/libcoveofds/geojson.py +++ b/libcoveofds/geojson.py @@ -69,6 +69,13 @@ def get_meta_json(self) -> dict: out["spans_output_field_coverage"][key] = {"count": 1} else: out["spans_output_field_coverage"][key]["count"] += 1 + # Any geometries? + out["any_spans_with_geometry"] = bool( + [True for s in self._spans_geojson_features if s.get("geometry")] + ) + out["any_nodes_with_geometry"] = bool( + [True for n in self._nodes_geojson_features if n.get("geometry")] + ) # return return out diff --git a/tests/fixtures/json_to_geojson/basic_1.expected.meta.json b/tests/fixtures/json_to_geojson/basic_1.expected.meta.json index 27a754b..dc73398 100644 --- a/tests/fixtures/json_to_geojson/basic_1.expected.meta.json +++ b/tests/fixtures/json_to_geojson/basic_1.expected.meta.json @@ -116,5 +116,7 @@ "/features/properties/network/name": { "count": 1 } - } + }, + "any_spans_with_geometry": true, + "any_nodes_with_geometry": true } \ No newline at end of file diff --git a/tests/fixtures/json_to_geojson/no_geometry_1.expected.meta.json b/tests/fixtures/json_to_geojson/no_geometry_1.expected.meta.json index 018ae8a..3a3b805 100644 --- a/tests/fixtures/json_to_geojson/no_geometry_1.expected.meta.json +++ b/tests/fixtures/json_to_geojson/no_geometry_1.expected.meta.json @@ -86,5 +86,7 @@ "/features/properties/network/name": { "count": 1 } - } + }, + "any_spans_with_geometry": false, + "any_nodes_with_geometry": false } \ No newline at end of file diff --git a/tests/fixtures/json_to_geojson/organisations_1.expected.meta.json b/tests/fixtures/json_to_geojson/organisations_1.expected.meta.json index 22cc0ce..bf1c0fe 100644 --- a/tests/fixtures/json_to_geojson/organisations_1.expected.meta.json +++ b/tests/fixtures/json_to_geojson/organisations_1.expected.meta.json @@ -176,5 +176,7 @@ "/features/properties/network/name": { "count": 1 } - } + }, + "any_spans_with_geometry": true, + "any_nodes_with_geometry": true } \ No newline at end of file diff --git a/tests/fixtures/json_to_geojson/phases_1.expected.meta.json b/tests/fixtures/json_to_geojson/phases_1.expected.meta.json index 0705023..962209a 100644 --- a/tests/fixtures/json_to_geojson/phases_1.expected.meta.json +++ b/tests/fixtures/json_to_geojson/phases_1.expected.meta.json @@ -200,5 +200,7 @@ "/features/properties/network/contracts/relatedPhases/description": { "count": 1 } - } + }, + "any_spans_with_geometry": true, + "any_nodes_with_geometry": true } \ No newline at end of file