diff --git a/nextplot/__about__.py b/nextplot/__about__.py index c7f5b95..b67ea67 100644 --- a/nextplot/__about__.py +++ b/nextplot/__about__.py @@ -1 +1 @@ -__version__ = "v0.1.7" +__version__ = "v0.1.8" diff --git a/nextplot/geojson.py b/nextplot/geojson.py index 113781f..371155c 100644 --- a/nextplot/geojson.py +++ b/nextplot/geojson.py @@ -104,14 +104,15 @@ def parse( Parses the geojson data object(s) from the file(s). """ # Load json data - content_geojson, _ = common.load_data(input_geojson, "") + content, _ = common.load_data(input_geojson, "") + json_content = json.loads(content) # Extract geojsons if jpath_geojson: expression = jsonpath_ng.parse(jpath_geojson) - geojsons = [json.loads(match.value) for match in expression.find(content_geojson)] + geojsons = [match.value for match in expression.find(json_content)] else: - geojsons = [json.loads(content_geojson)] + geojsons = [json_content] return geojsons diff --git a/tests/test_cli.py b/tests/test_cli.py index 621d2ad..93d522f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -480,6 +480,23 @@ def test_map_plot_cli_geojson(): _run_geojson_test(test) +def test_map_plot_cli_geojson_nested(): + test = GeoJSONTest( + "geojson", + [ + "geojson", + "--input_geojson", + os.path.join(DATA_DIR, "geojson-nested-data.json"), + "--jpath_geojson", + "assets[*].content", + ], + os.path.join(OUTPUT_DIR, "geojson-nested-data.json.map.html"), + os.path.join(DATA_DIR, "geojson-nested-data.json.golden"), + os.path.join(DATA_DIR, "geojson-nested-data.json.map.html.golden"), + ) + _run_geojson_test(test) + + def test_progression_plot_cli_fleet_cloud_comparison(): test = ProgressionTest( "fleet-cloud-comparison", @@ -507,5 +524,6 @@ def test_progression_plot_cli_fleet_cloud_comparison(): test_map_plot_cli_paris_point() test_map_plot_cli_paris_route_indexed() test_map_plot_cli_geojson() + test_map_plot_cli_geojson_nested() test_progression_plot_cli_fleet_cloud_comparison() print("Everything passed") diff --git a/tests/testdata/geojson-nested-data.json b/tests/testdata/geojson-nested-data.json new file mode 100644 index 0000000..dc234b9 --- /dev/null +++ b/tests/testdata/geojson-nested-data.json @@ -0,0 +1,39 @@ +{ + "assets": [ + { + "type": "geojson", + "content": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [-74.076, 4.598] + }, + "properties": {} + }, + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [-75.1649, 39.9525] + }, + "properties": {} + } + ] + } + }, + { + "type": "geojson", + "content": { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [7.6281, 51.962] + }, + "properties": {} + } + } + ] +} diff --git a/tests/testdata/geojson-nested-data.json.golden b/tests/testdata/geojson-nested-data.json.golden new file mode 100644 index 0000000..e69de29 diff --git a/tests/testdata/geojson-nested-data.json.map.html.golden b/tests/testdata/geojson-nested-data.json.map.html.golden new file mode 100644 index 0000000..74b6708 --- /dev/null +++ b/tests/testdata/geojson-nested-data.json.map.html.golden @@ -0,0 +1,226 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file