From 17f0b0b3bc65ffba39bf6f22a12b2cc7fcb9bafd Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 6 Jul 2019 02:03:50 +0200 Subject: Proof-of-concept of JSON export limited to PrimeMeridian (refs #1545) --- test/unit/test_datum.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/unit/test_datum.cpp b/test/unit/test_datum.cpp index fa53ff85..121b7c88 100644 --- a/test/unit/test_datum.cpp +++ b/test/unit/test_datum.cpp @@ -205,6 +205,34 @@ TEST(datum, prime_meridian_to_PROJString) { // --------------------------------------------------------------------------- +TEST(datum, prime_meridian_to_JSON) { + + EXPECT_EQ( + PrimeMeridian::GREENWICH->exportToJSON(JSONFormatter::create().get()), + "{\n" + " \"type\": \"PrimeMeridian\",\n" + " \"name\": \"Greenwich\",\n" + " \"longitude\": {\n" + " \"value\": 0,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"degree\",\n" + " \"conversion_factor\": 0.0174532925199433,\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 9122\n" + " }\n" + " }\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8901\n" + " }\n" + "}"); +} + +// --------------------------------------------------------------------------- + TEST(datum, datum_with_ANCHOR) { auto datum = GeodeticReferenceFrame::create( PropertyMap().set(IdentifiedObject::NAME_KEY, "WGS_1984 with anchor"), -- cgit v1.2.3 From ece151aed1b4bf2634de5759f37fd7bc005e8313 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 6 Jul 2019 17:06:23 +0200 Subject: CRS JSON: export GeographicCRS and Projected CRS --- test/cli/testprojinfo_out.dist | 74 ++++++++++++++++++++++++++++++++++++++++++ test/unit/test_datum.cpp | 6 +--- 2 files changed, 75 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/cli/testprojinfo_out.dist b/test/cli/testprojinfo_out.dist index f742fa60..20ae544a 100644 --- a/test/cli/testprojinfo_out.dist +++ b/test/cli/testprojinfo_out.dist @@ -135,6 +135,80 @@ WKT1_ESRI: GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] +JSON: +{ + "type": "GeographicCRS", + "name": "WGS 84", + "datum": { + "type": "GeodeticReferenceFrame", + "name": "World Geodetic System 1984", + "ellipsoid": { + "type": "Ellipsoid", + "name": "WGS 84", + "semi_major_axis": { + "value": 6378137, + "unit": { + "type": "LinearUnit", + "name": "metre", + "conversion_factor": 1 + } + }, + "inverse_flattening": 298.257223563 + }, + "prime_meridian": { + "type": "PrimeMeridian", + "name": "Greenwich", + "longitude": { + "value": 0, + "unit": { + "type": "AngularUnit", + "name": "degree", + "conversion_factor": 0.0174532925199433 + } + } + } + }, + "coordinate_system": { + "type": "CoordinateSystem", + "subtype": "ellipsoidal", + "axis": [ + { + "type": "Axis", + "name": "Geodetic latitude", + "abbreviation": "Lat", + "direction": "north", + "unit": { + "type": "AngularUnit", + "name": "degree", + "conversion_factor": 0.0174532925199433 + } + }, + { + "type": "Axis", + "name": "Geodetic longitude", + "abbreviation": "Lon", + "direction": "east", + "unit": { + "type": "AngularUnit", + "name": "degree", + "conversion_factor": 0.0174532925199433 + } + } + ] + }, + "area": "World", + "bbox": { + "south_latitude": -90, + "west_longitude": -180, + "north_latitude": 90, + "east_longitude": 180 + }, + "id": { + "authority": "EPSG", + "code": 4326 + } +} + Testing projinfo -s EPSG:4326 -t EPSG:32631 Candidate operations found: 1 ------------------------------------- diff --git a/test/unit/test_datum.cpp b/test/unit/test_datum.cpp index 121b7c88..cf2e2f3a 100644 --- a/test/unit/test_datum.cpp +++ b/test/unit/test_datum.cpp @@ -217,11 +217,7 @@ TEST(datum, prime_meridian_to_JSON) { " \"unit\": {\n" " \"type\": \"AngularUnit\",\n" " \"name\": \"degree\",\n" - " \"conversion_factor\": 0.0174532925199433,\n" - " \"id\": {\n" - " \"authority\": \"EPSG\",\n" - " \"code\": 9122\n" - " }\n" + " \"conversion_factor\": 0.0174532925199433\n" " }\n" " },\n" " \"id\": {\n" -- cgit v1.2.3 From ec49c9cd0aa9de24623920b8de226daf05a0e90f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 8 Aug 2019 19:18:26 +0200 Subject: projinfo: rename JSON to PROJJSON --- test/cli/testprojinfo_out.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/cli/testprojinfo_out.dist b/test/cli/testprojinfo_out.dist index 20ae544a..530a0426 100644 --- a/test/cli/testprojinfo_out.dist +++ b/test/cli/testprojinfo_out.dist @@ -135,7 +135,7 @@ WKT1_ESRI: GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] -JSON: +PROJJSON: { "type": "GeographicCRS", "name": "WGS 84", -- cgit v1.2.3 From 89f2cc7ec4178a369e73e9cd115a2552a55d870a Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 8 Aug 2019 20:04:20 +0200 Subject: PROJJSON export: use more compact form --- test/cli/testprojinfo_out.dist | 37 +++---------------------------------- test/unit/test_datum.cpp | 27 +++++++++++++++++++-------- 2 files changed, 22 insertions(+), 42 deletions(-) (limited to 'test') diff --git a/test/cli/testprojinfo_out.dist b/test/cli/testprojinfo_out.dist index 530a0426..73751b99 100644 --- a/test/cli/testprojinfo_out.dist +++ b/test/cli/testprojinfo_out.dist @@ -143,56 +143,25 @@ PROJJSON: "type": "GeodeticReferenceFrame", "name": "World Geodetic System 1984", "ellipsoid": { - "type": "Ellipsoid", "name": "WGS 84", - "semi_major_axis": { - "value": 6378137, - "unit": { - "type": "LinearUnit", - "name": "metre", - "conversion_factor": 1 - } - }, + "semi_major_axis": 6378137, "inverse_flattening": 298.257223563 - }, - "prime_meridian": { - "type": "PrimeMeridian", - "name": "Greenwich", - "longitude": { - "value": 0, - "unit": { - "type": "AngularUnit", - "name": "degree", - "conversion_factor": 0.0174532925199433 - } - } } }, "coordinate_system": { - "type": "CoordinateSystem", "subtype": "ellipsoidal", "axis": [ { - "type": "Axis", "name": "Geodetic latitude", "abbreviation": "Lat", "direction": "north", - "unit": { - "type": "AngularUnit", - "name": "degree", - "conversion_factor": 0.0174532925199433 - } + "unit": "degree" }, { - "type": "Axis", "name": "Geodetic longitude", "abbreviation": "Lon", "direction": "east", - "unit": { - "type": "AngularUnit", - "name": "degree", - "conversion_factor": 0.0174532925199433 - } + "unit": "degree" } ] }, diff --git a/test/unit/test_datum.cpp b/test/unit/test_datum.cpp index cf2e2f3a..d8fab1f0 100644 --- a/test/unit/test_datum.cpp +++ b/test/unit/test_datum.cpp @@ -212,19 +212,30 @@ TEST(datum, prime_meridian_to_JSON) { "{\n" " \"type\": \"PrimeMeridian\",\n" " \"name\": \"Greenwich\",\n" - " \"longitude\": {\n" - " \"value\": 0,\n" - " \"unit\": {\n" - " \"type\": \"AngularUnit\",\n" - " \"name\": \"degree\",\n" - " \"conversion_factor\": 0.0174532925199433\n" - " }\n" - " },\n" + " \"longitude\": 0,\n" " \"id\": {\n" " \"authority\": \"EPSG\",\n" " \"code\": 8901\n" " }\n" "}"); + + EXPECT_EQ(PrimeMeridian::PARIS->exportToJSON(JSONFormatter::create().get()), + "{\n" + " \"type\": \"PrimeMeridian\",\n" + " \"name\": \"Paris\",\n" + " \"longitude\": {\n" + " \"value\": 2.5969213,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"grad\",\n" + " \"conversion_factor\": 0.015707963267949\n" + " }\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8903\n" + " }\n" + "}"); } // --------------------------------------------------------------------------- -- cgit v1.2.3 From 81bd57dfd8cfae609288643d1b09a4805f1bcded Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 9 Aug 2019 12:59:49 +0200 Subject: createFromUserInput(): add capability to import PROJJSON --- test/unit/test_io.cpp | 480 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 480 insertions(+) (limited to 'test') diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index f0f462c2..c993c5e4 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -9132,3 +9132,483 @@ TEST(wkt_export, invalid_angular_unit) { WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get()), FormattingException); } + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_ellipsoid_flattened_sphere) { + auto json = "{\n" + " \"type\": \"Ellipsoid\",\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563,\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 7030\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto ellps = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(ellps != nullptr); + EXPECT_EQ(ellps->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_ellipsoid_major_minor_custom_unit) { + auto json = "{\n" + " \"type\": \"Ellipsoid\",\n" + " \"name\": \"foo\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"semi_minor_axis\": {\n" + " \"value\": 6370000,\n" + " \"unit\": {\n" + " \"type\": \"LinearUnit\",\n" + " \"name\": \"my_unit\",\n" + " \"conversion_factor\": 2\n" + " }\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto ellps = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(ellps != nullptr); + EXPECT_EQ(ellps->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_ellipsoid_sphere) { + auto json = "{\n" + " \"type\": \"Ellipsoid\",\n" + " \"name\": \"Sphere\",\n" + " \"radius\": 6371000,\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 7035\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto ellps = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(ellps != nullptr); + EXPECT_EQ(ellps->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_ellipsoid_errors) { + EXPECT_THROW(createFromUserInput("{", nullptr), ParsingException); + EXPECT_THROW(createFromUserInput("{}", nullptr), ParsingException); + EXPECT_THROW(createFromUserInput("{ \"type\": \"Ellipsoid\" }", nullptr), + ParsingException); + EXPECT_THROW(createFromUserInput( + "{ \"type\": \"Ellipsoid\", \"name\": \"foo\" }", nullptr), + ParsingException); + EXPECT_THROW( + createFromUserInput( + "{ \"type\": \"Ellipsoid\", \"name\": \"foo\", \"radius\": null }", + nullptr), + ParsingException); + EXPECT_THROW(createFromUserInput("{ \"type\": \"Ellipsoid\", \"name\": " + "\"foo\", \"semi_major_axis\": 1 }", + nullptr), + ParsingException); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_prime_meridian) { + auto json = "{\n" + " \"type\": \"PrimeMeridian\",\n" + " \"name\": \"Paris\",\n" + " \"longitude\": {\n" + " \"value\": 2.5969213,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"grad\",\n" + " \"conversion_factor\": 0.0157079632679489\n" + " }\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto pm = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(pm != nullptr); + EXPECT_EQ(pm->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_prime_meridian_errors) { + EXPECT_THROW(createFromUserInput("{ \"type\": \"PrimeMeridian\", \"name\": " + "\"foo\" }", + nullptr), + ParsingException); + EXPECT_THROW(createFromUserInput("{ \"type\": \"PrimeMeridian\", \"name\": " + "\"foo\", \"longitude\": null }", + nullptr), + ParsingException); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, + json_import_geodetic_reference_frame_with_implicit_prime_meridian) { + auto json = "{\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto gdr = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(gdr != nullptr); + EXPECT_EQ(gdr->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, + json_import_geodetic_reference_frame_with_explicit_prime_meridian) { + auto json = "{\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"Nouvelle Triangulation Francaise (Paris)\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"Clarke 1880 (IGN)\",\n" + " \"semi_major_axis\": 6378249.2,\n" + " \"semi_minor_axis\": 6356515\n" + " },\n" + " \"prime_meridian\": {\n" + " \"name\": \"Paris\",\n" + " \"longitude\": {\n" + " \"value\": 2.5969213,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"grad\",\n" + " \"conversion_factor\": 0.0157079632679489\n" + " }\n" + " }\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto gdr = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(gdr != nullptr); + EXPECT_EQ(gdr->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_geodetic_reference_frame_errors) { + EXPECT_THROW( + createFromUserInput( + "{ \"type\": \"GeodeticReferenceFrame\", \"name\": \"foo\" }", + nullptr), + ParsingException); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_several_usages) { + auto json = "{\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " },\n" + " \"usages\": [\n" + " {\n" + " \"area\": \"World\",\n" + " \"bbox\": {\n" + " \"south_latitude\": -90,\n" + " \"west_longitude\": -180,\n" + " \"north_latitude\": 90,\n" + " \"east_longitude\": 180\n" + " }\n" + " },\n" + " {\n" + " \"scope\": \"my_scope\",\n" + " \"area\": \"my_area\"\n" + " }\n" + " ]\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto gdr = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(gdr != nullptr); + EXPECT_EQ(gdr->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_geographic_crs) { + auto json = "{\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"area\": \"World\",\n" + " \"bbox\": {\n" + " \"south_latitude\": -90,\n" + " \"west_longitude\": -180,\n" + " \"north_latitude\": 90,\n" + " \"east_longitude\": 180\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 4326\n" + " },\n" + " \"remarks\": \"my_remarks\"\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto gcrs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(gcrs != nullptr); + EXPECT_EQ(gcrs->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_geographic_crs_errors) { + EXPECT_THROW( + createFromUserInput( + "{ \"type\": \"GeographicCRS\", \"name\": \"foo\" }", nullptr), + ParsingException); + EXPECT_THROW( + createFromUserInput("{\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " }\n" + "}", + nullptr), + ParsingException); + EXPECT_THROW( + createFromUserInput("{\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Easting\",\n" + " \"abbreviation\": \"E\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Northing\",\n" + " \"abbreviation\": \"N\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}", + nullptr), + ParsingException); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_geocentric_crs) { + auto json = "{\n" + " \"type\": \"GeodeticCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geocentric X\",\n" + " \"abbreviation\": \"X\",\n" + " \"direction\": \"geocentricX\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Geocentric Y\",\n" + " \"abbreviation\": \"Y\",\n" + " \"direction\": \"geocentricY\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Geocentric Z\",\n" + " \"abbreviation\": \"Z\",\n" + " \"direction\": \"geocentricZ\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto gdcrs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(gdcrs != nullptr); + EXPECT_EQ(gdcrs->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_projected_crs) { + auto json = "{\n" + " \"type\": \"ProjectedCRS\",\n" + " \"name\": \"WGS 84 / UTM zone 31N\",\n" + " \"base_crs\": {\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 4326\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"UTM zone 31N\",\n" + " \"method\": {\n" + " \"name\": \"Transverse Mercator\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 9807\n" + " }\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"Latitude of natural origin\",\n" + " \"value\": 0,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8801\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Longitude of natural origin\",\n" + " \"value\": 3,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8802\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Scale factor at natural origin\",\n" + " \"value\": 0.9996,\n" + " \"unit\": \"unity\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8805\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"False easting\",\n" + " \"value\": 500000,\n" + " \"unit\": \"metre\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8806\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"False northing\",\n" + " \"value\": 0,\n" + " \"unit\": \"metre\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8807\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Easting\",\n" + " \"abbreviation\": \"E\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Northing\",\n" + " \"abbreviation\": \"N\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto pcrs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(pcrs != nullptr); + EXPECT_EQ(pcrs->exportToJSON((JSONFormatter::create().get())), json); +} -- cgit v1.2.3 From f0d766e45640800412c08a7cb9ab4f8823d88d05 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 9 Aug 2019 17:10:20 +0200 Subject: PROJSJON: add import/export of VerticalCRS, CompoundCRS, BoundCRS, Transformation and ConcatenatedOperation --- test/unit/test_io.cpp | 790 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 790 insertions(+) (limited to 'test') diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index c993c5e4..d3c4c8ec 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -9612,3 +9612,793 @@ TEST(wkt_export, json_import_projected_crs) { ASSERT_TRUE(pcrs != nullptr); EXPECT_EQ(pcrs->exportToJSON((JSONFormatter::create().get())), json); } + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_compound_crs) { + auto json = "{\n" + " \"type\": \"CompoundCRS\",\n" + " \"name\": \"WGS 84 + EGM2008 height\",\n" + " \"components\": [\n" + " {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 4326\n" + " }\n" + " },\n" + " {\n" + " \"type\": \"VerticalCRS\",\n" + " \"name\": \"EGM2008 height\",\n" + " \"datum\": {\n" + " \"type\": \"VerticalReferenceFrame\",\n" + " \"name\": \"EGM2008 geoid\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"vertical\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Gravity-related height\",\n" + " \"abbreviation\": \"H\",\n" + " \"direction\": \"up\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 3855\n" + " }\n" + " }\n" + " ]\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto compoundCRS = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(compoundCRS != nullptr); + EXPECT_EQ(compoundCRS->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_bound_crs) { + auto json = + "{\n" + " \"type\": \"BoundCRS\",\n" + " \"source_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"unknown\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"Unknown based on GRS80 ellipsoid\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"GRS 1980\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257222101,\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 7019\n" + " }\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Longitude\",\n" + " \"abbreviation\": \"lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Latitude\",\n" + " \"abbreviation\": \"lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"target_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Latitude\",\n" + " \"abbreviation\": \"lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Longitude\",\n" + " \"abbreviation\": \"lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 4326\n" + " }\n" + " },\n" + " \"transformation\": {\n" + " \"name\": \"unknown to WGS84\",\n" + " \"method\": {\n" + " \"name\": \"NTv2\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 9615\n" + " }\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"Latitude and longitude difference file\",\n" + " \"value\": \"@foo\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8656\n" + " }\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto boundCRS = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(boundCRS != nullptr); + EXPECT_EQ(boundCRS->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_transformation) { + auto json = "{\n" + " \"type\": \"Transformation\",\n" + " \"name\": \"GDA94 to GDA2020 (1)\",\n" + " \"source_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"GDA94\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"Geocentric Datum of Australia 1994\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"GRS 1980\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257222101\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"target_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"GDA2020\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"Geocentric Datum of Australia 2020\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"GRS 1980\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257222101\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"method\": {\n" + " \"name\": \"Coordinate Frame rotation (geog2D domain)\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 9607\n" + " }\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"X-axis translation\",\n" + " \"value\": 61.55,\n" + " \"unit\": {\n" + " \"type\": \"LinearUnit\",\n" + " \"name\": \"millimetre\",\n" + " \"conversion_factor\": 0.001\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8605\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Y-axis translation\",\n" + " \"value\": -10.87,\n" + " \"unit\": {\n" + " \"type\": \"LinearUnit\",\n" + " \"name\": \"millimetre\",\n" + " \"conversion_factor\": 0.001\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8606\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Z-axis translation\",\n" + " \"value\": -40.19,\n" + " \"unit\": {\n" + " \"type\": \"LinearUnit\",\n" + " \"name\": \"millimetre\",\n" + " \"conversion_factor\": 0.001\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8607\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"X-axis rotation\",\n" + " \"value\": -39.4924,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"milliarc-second\",\n" + " \"conversion_factor\": 4.84813681109536e-09\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8608\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Y-axis rotation\",\n" + " \"value\": -32.7221,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"milliarc-second\",\n" + " \"conversion_factor\": 4.84813681109536e-09\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8609\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Z-axis rotation\",\n" + " \"value\": -32.8979,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"milliarc-second\",\n" + " \"conversion_factor\": 4.84813681109536e-09\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8610\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Scale difference\",\n" + " \"value\": -9.994,\n" + " \"unit\": {\n" + " \"type\": \"ScaleUnit\",\n" + " \"name\": \"parts per billion\",\n" + " \"conversion_factor\": 1e-09\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8611\n" + " }\n" + " }\n" + " ],\n" + " \"accuracy\": \"0.01\",\n" + " \"scope\": \"scope\",\n" + " \"area\": \"Australia - GDA\",\n" + " \"bbox\": {\n" + " \"south_latitude\": -60.56,\n" + " \"west_longitude\": 93.41,\n" + " \"north_latitude\": -8.47,\n" + " \"east_longitude\": 173.35\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8048\n" + " },\n" + " \"remarks\": \"foo\"\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto transf = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(transf != nullptr); + EXPECT_EQ(transf->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(wkt_export, json_import_concatenated_operation) { + auto json = + "{\n" + " \"type\": \"ConcatenatedOperation\",\n" + " \"name\": \"Inverse of Vicgrid + GDA94 to GDA2020 (1)\",\n" + " \"source_crs\": {\n" + " \"type\": \"ProjectedCRS\",\n" + " \"name\": \"GDA94 / Vicgrid\",\n" + " \"base_crs\": {\n" + " \"name\": \"GDA94\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"Geocentric Datum of Australia 1994\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"GRS 1980\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257222101\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 4283\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"Vicgrid\",\n" + " \"method\": {\n" + " \"name\": \"Lambert Conic Conformal (2SP)\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 9802\n" + " }\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"Latitude of false origin\",\n" + " \"value\": -37,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8821\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Longitude of false origin\",\n" + " \"value\": 145,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8822\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Latitude of 1st standard parallel\",\n" + " \"value\": -36,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8823\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Latitude of 2nd standard parallel\",\n" + " \"value\": -38,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8824\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Easting at false origin\",\n" + " \"value\": 2500000,\n" + " \"unit\": \"metre\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8826\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Northing at false origin\",\n" + " \"value\": 2500000,\n" + " \"unit\": \"metre\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8827\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Easting\",\n" + " \"abbreviation\": \"E\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Northing\",\n" + " \"abbreviation\": \"N\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 3111\n" + " }\n" + " },\n" + " \"target_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"GDA2020\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"Geocentric Datum of Australia 2020\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"GRS 1980\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257222101\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 7844\n" + " }\n" + " },\n" + " \"steps\": [\n" + " {\n" + " \"type\": \"Conversion\",\n" + " \"name\": \"Inverse of Vicgrid\",\n" + " \"method\": {\n" + " \"name\": \"Inverse of Lambert Conic Conformal (2SP)\",\n" + " \"id\": {\n" + " \"authority\": \"INVERSE(EPSG)\",\n" + " \"code\": 9802\n" + " }\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"Latitude of false origin\",\n" + " \"value\": -37,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8821\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Longitude of false origin\",\n" + " \"value\": 145,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8822\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Latitude of 1st standard parallel\",\n" + " \"value\": -36,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8823\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Latitude of 2nd standard parallel\",\n" + " \"value\": -38,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8824\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Easting at false origin\",\n" + " \"value\": 2500000,\n" + " \"unit\": \"metre\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8826\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Northing at false origin\",\n" + " \"value\": 2500000,\n" + " \"unit\": \"metre\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8827\n" + " }\n" + " }\n" + " ],\n" + " \"id\": {\n" + " \"authority\": \"INVERSE(EPSG)\",\n" + " \"code\": 17361\n" + " }\n" + " },\n" + " {\n" + " \"type\": \"Transformation\",\n" + " \"name\": \"GDA94 to GDA2020 (1)\",\n" + " \"source_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"GDA94\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"Geocentric Datum of Australia 1994\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"GRS 1980\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257222101\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 4283\n" + " }\n" + " },\n" + " \"target_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"GDA2020\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"Geocentric Datum of Australia 2020\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"GRS 1980\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257222101\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geodetic latitude\",\n" + " \"abbreviation\": \"Lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Geodetic longitude\",\n" + " \"abbreviation\": \"Lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 7844\n" + " }\n" + " },\n" + " \"method\": {\n" + " \"name\": \"Coordinate Frame rotation (geog2D domain)\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 9607\n" + " }\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"X-axis translation\",\n" + " \"value\": 61.55,\n" + " \"unit\": {\n" + " \"type\": \"LinearUnit\",\n" + " \"name\": \"millimetre\",\n" + " \"conversion_factor\": 0.001\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8605\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Y-axis translation\",\n" + " \"value\": -10.87,\n" + " \"unit\": {\n" + " \"type\": \"LinearUnit\",\n" + " \"name\": \"millimetre\",\n" + " \"conversion_factor\": 0.001\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8606\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Z-axis translation\",\n" + " \"value\": -40.19,\n" + " \"unit\": {\n" + " \"type\": \"LinearUnit\",\n" + " \"name\": \"millimetre\",\n" + " \"conversion_factor\": 0.001\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8607\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"X-axis rotation\",\n" + " \"value\": -39.4924,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"milliarc-second\",\n" + " \"conversion_factor\": 4.84813681109536e-09\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8608\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Y-axis rotation\",\n" + " \"value\": -32.7221,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"milliarc-second\",\n" + " \"conversion_factor\": 4.84813681109536e-09\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8609\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Z-axis rotation\",\n" + " \"value\": -32.8979,\n" + " \"unit\": {\n" + " \"type\": \"AngularUnit\",\n" + " \"name\": \"milliarc-second\",\n" + " \"conversion_factor\": 4.84813681109536e-09\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8610\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Scale difference\",\n" + " \"value\": -9.994,\n" + " \"unit\": {\n" + " \"type\": \"ScaleUnit\",\n" + " \"name\": \"parts per billion\",\n" + " \"conversion_factor\": 1e-09\n" + " },\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8611\n" + " }\n" + " }\n" + " ],\n" + " \"accuracy\": \"0.01\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8048\n" + " },\n" + " \"remarks\": \"remarks\"\n" + " }\n" + " ],\n" + " \"area\": \"Australia - GDA\",\n" + " \"bbox\": {\n" + " \"south_latitude\": -60.56,\n" + " \"west_longitude\": 93.41,\n" + " \"north_latitude\": -8.47,\n" + " \"east_longitude\": 173.35\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto concat = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(concat != nullptr); + EXPECT_EQ(concat->exportToJSON((JSONFormatter::create().get())), json); +} -- cgit v1.2.3 From 99b25fcf9009a6cc098cf2e0703f994d74968985 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 9 Aug 2019 17:50:35 +0200 Subject: C API: add proj_as_projjson() --- test/unit/test_c_api.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'test') diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index bfbae1a5..5649ca9f 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -3489,4 +3489,56 @@ TEST_F(CApi, proj_concatoperation_get_step) { } } +// --------------------------------------------------------------------------- + +TEST_F(CApi, proj_as_projjson) { + auto obj = proj_create( + m_ctxt, + Ellipsoid::WGS84->exportToJSON(JSONFormatter::create().get()).c_str()); + ObjectKeeper keeper(obj); + ASSERT_NE(obj, nullptr); + + { + auto projjson = proj_as_projjson(m_ctxt, obj, nullptr); + ASSERT_NE(projjson, nullptr); + EXPECT_EQ(std::string(projjson), + "{\n" + " \"type\": \"Ellipsoid\",\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563,\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 7030\n" + " }\n" + "}"); + } + { + const char *const options[] = {"INDENTATION_WIDTH=4", nullptr}; + auto projjson = proj_as_projjson(m_ctxt, obj, options); + ASSERT_NE(projjson, nullptr); + EXPECT_EQ(std::string(projjson), + "{\n" + " \"type\": \"Ellipsoid\",\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563,\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 7030\n" + " }\n" + "}"); + } + { + const char *const options[] = {"MULTILINE=NO", nullptr}; + auto projjson = proj_as_projjson(m_ctxt, obj, options); + ASSERT_NE(projjson, nullptr); + EXPECT_EQ(std::string(projjson), + "{\"type\":\"Ellipsoid\",\"name\":\"WGS 84\"," + "\"semi_major_axis\":6378137," + "\"inverse_flattening\":298.257223563," + "\"id\":{\"authority\":\"EPSG\",\"code\":7030}}"); + } +} + } // namespace -- cgit v1.2.3 From 63981af418d84749cd4d70752f83fd551100389f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 10 Aug 2019 15:15:44 +0200 Subject: PROJJSON: add support for DatumEnsemble and Dynamic[Geodetic|Vertical]ReferenceFrame --- test/unit/test_io.cpp | 266 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 240 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index d3c4c8ec..67fdcb77 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -9135,7 +9135,7 @@ TEST(wkt_export, invalid_angular_unit) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_ellipsoid_flattened_sphere) { +TEST(json_import, ellipsoid_flattened_sphere) { auto json = "{\n" " \"type\": \"Ellipsoid\",\n" " \"name\": \"WGS 84\",\n" @@ -9154,7 +9154,7 @@ TEST(wkt_export, json_import_ellipsoid_flattened_sphere) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_ellipsoid_major_minor_custom_unit) { +TEST(json_import, ellipsoid_major_minor_custom_unit) { auto json = "{\n" " \"type\": \"Ellipsoid\",\n" " \"name\": \"foo\",\n" @@ -9176,7 +9176,7 @@ TEST(wkt_export, json_import_ellipsoid_major_minor_custom_unit) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_ellipsoid_sphere) { +TEST(json_import, ellipsoid_sphere) { auto json = "{\n" " \"type\": \"Ellipsoid\",\n" " \"name\": \"Sphere\",\n" @@ -9194,7 +9194,7 @@ TEST(wkt_export, json_import_ellipsoid_sphere) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_ellipsoid_errors) { +TEST(json_import, ellipsoid_errors) { EXPECT_THROW(createFromUserInput("{", nullptr), ParsingException); EXPECT_THROW(createFromUserInput("{}", nullptr), ParsingException); EXPECT_THROW(createFromUserInput("{ \"type\": \"Ellipsoid\" }", nullptr), @@ -9215,7 +9215,7 @@ TEST(wkt_export, json_import_ellipsoid_errors) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_prime_meridian) { +TEST(json_import, prime_meridian) { auto json = "{\n" " \"type\": \"PrimeMeridian\",\n" " \"name\": \"Paris\",\n" @@ -9236,7 +9236,7 @@ TEST(wkt_export, json_import_prime_meridian) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_prime_meridian_errors) { +TEST(json_import, prime_meridian_errors) { EXPECT_THROW(createFromUserInput("{ \"type\": \"PrimeMeridian\", \"name\": " "\"foo\" }", nullptr), @@ -9249,8 +9249,7 @@ TEST(wkt_export, json_import_prime_meridian_errors) { // --------------------------------------------------------------------------- -TEST(wkt_export, - json_import_geodetic_reference_frame_with_implicit_prime_meridian) { +TEST(json_import, geodetic_reference_frame_with_implicit_prime_meridian) { auto json = "{\n" " \"type\": \"GeodeticReferenceFrame\",\n" " \"name\": \"World Geodetic System 1984\",\n" @@ -9261,15 +9260,14 @@ TEST(wkt_export, " }\n" "}"; auto obj = createFromUserInput(json, nullptr); - auto gdr = nn_dynamic_pointer_cast(obj); - ASSERT_TRUE(gdr != nullptr); - EXPECT_EQ(gdr->exportToJSON((JSONFormatter::create().get())), json); + auto grf = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(grf != nullptr); + EXPECT_EQ(grf->exportToJSON((JSONFormatter::create().get())), json); } // --------------------------------------------------------------------------- -TEST(wkt_export, - json_import_geodetic_reference_frame_with_explicit_prime_meridian) { +TEST(json_import, geodetic_reference_frame_with_explicit_prime_meridian) { auto json = "{\n" " \"type\": \"GeodeticReferenceFrame\",\n" " \"name\": \"Nouvelle Triangulation Francaise (Paris)\",\n" @@ -9291,14 +9289,35 @@ TEST(wkt_export, " }\n" "}"; auto obj = createFromUserInput(json, nullptr); - auto gdr = nn_dynamic_pointer_cast(obj); - ASSERT_TRUE(gdr != nullptr); - EXPECT_EQ(gdr->exportToJSON((JSONFormatter::create().get())), json); + auto grf = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(grf != nullptr); + EXPECT_EQ(grf->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, + dynamic_geodetic_reference_frame_with_implicit_prime_meridian) { + auto json = "{\n" + " \"type\": \"DynamicGeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"frame_reference_epoch\": 1,\n" + " \"deformation_model\": \"foo\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto dgrf = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(dgrf != nullptr); + EXPECT_EQ(dgrf->exportToJSON((JSONFormatter::create().get())), json); } // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_geodetic_reference_frame_errors) { +TEST(json_import, geodetic_reference_frame_errors) { EXPECT_THROW( createFromUserInput( "{ \"type\": \"GeodeticReferenceFrame\", \"name\": \"foo\" }", @@ -9308,7 +9327,22 @@ TEST(wkt_export, json_import_geodetic_reference_frame_errors) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_several_usages) { +TEST(json_import, dynamic_vertical_reference_frame) { + auto json = "{\n" + " \"type\": \"DynamicVerticalReferenceFrame\",\n" + " \"name\": \"bar\",\n" + " \"frame_reference_epoch\": 1,\n" + " \"deformation_model\": \"foo\"\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto dvrf = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(dvrf != nullptr); + EXPECT_EQ(dvrf->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, several_usages) { auto json = "{\n" " \"type\": \"GeodeticReferenceFrame\",\n" " \"name\": \"World Geodetic System 1984\",\n" @@ -9341,7 +9375,7 @@ TEST(wkt_export, json_import_several_usages) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_geographic_crs) { +TEST(json_import, geographic_crs) { auto json = "{\n" " \"type\": \"GeographicCRS\",\n" " \"name\": \"WGS 84\",\n" @@ -9392,7 +9426,7 @@ TEST(wkt_export, json_import_geographic_crs) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_geographic_crs_errors) { +TEST(json_import, geographic_crs_errors) { EXPECT_THROW( createFromUserInput( "{ \"type\": \"GeographicCRS\", \"name\": \"foo\" }", nullptr), @@ -9450,7 +9484,7 @@ TEST(wkt_export, json_import_geographic_crs_errors) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_geocentric_crs) { +TEST(json_import, geocentric_crs) { auto json = "{\n" " \"type\": \"GeodeticCRS\",\n" " \"name\": \"WGS 84\",\n" @@ -9495,7 +9529,7 @@ TEST(wkt_export, json_import_geocentric_crs) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_projected_crs) { +TEST(json_import, projected_crs) { auto json = "{\n" " \"type\": \"ProjectedCRS\",\n" " \"name\": \"WGS 84 / UTM zone 31N\",\n" @@ -9615,7 +9649,7 @@ TEST(wkt_export, json_import_projected_crs) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_compound_crs) { +TEST(json_import, compound_crs) { auto json = "{\n" " \"type\": \"CompoundCRS\",\n" " \"name\": \"WGS 84 + EGM2008 height\",\n" @@ -9687,7 +9721,7 @@ TEST(wkt_export, json_import_compound_crs) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_bound_crs) { +TEST(json_import, bound_crs) { auto json = "{\n" " \"type\": \"BoundCRS\",\n" @@ -9788,7 +9822,7 @@ TEST(wkt_export, json_import_bound_crs) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_transformation) { +TEST(json_import, transformation) { auto json = "{\n" " \"type\": \"Transformation\",\n" " \"name\": \"GDA94 to GDA2020 (1)\",\n" @@ -9975,7 +10009,7 @@ TEST(wkt_export, json_import_transformation) { // --------------------------------------------------------------------------- -TEST(wkt_export, json_import_concatenated_operation) { +TEST(json_import, concatenated_operation) { auto json = "{\n" " \"type\": \"ConcatenatedOperation\",\n" @@ -10402,3 +10436,183 @@ TEST(wkt_export, json_import_concatenated_operation) { ASSERT_TRUE(concat != nullptr); EXPECT_EQ(concat->exportToJSON((JSONFormatter::create().get())), json); } + +// --------------------------------------------------------------------------- + +TEST(json_import, geographic_crs_with_datum_ensemble) { + auto json = "{\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum_ensemble\": {\n" + " \"name\": \"WGS 84 ensemble\",\n" + " \"members\": [\n" + " {\n" + " \"name\": \"World Geodetic System 1984 (Transit)\"\n" + " },\n" + " {\n" + " \"name\": \"World Geodetic System 1984 (G730)\"\n" + " }\n" + " ],\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " },\n" + " \"accuracy\": \"2\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Latitude\",\n" + " \"abbreviation\": \"lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Longitude\",\n" + " \"abbreviation\": \"lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + + auto expected_json = + "{\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum_ensemble\": {\n" + " \"name\": \"WGS 84 ensemble\",\n" + " \"members\": [\n" + " {\n" + " \"name\": \"World Geodetic System 1984 (Transit)\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 1166\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"World Geodetic System 1984 (G730)\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 1152\n" + " }\n" + " }\n" + " ],\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563,\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 7030\n" + " }\n" + " },\n" + " \"accuracy\": \"2\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Latitude\",\n" + " \"abbreviation\": \"lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Longitude\",\n" + " \"abbreviation\": \"lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + + { + // No database + auto obj = createFromUserInput(json, nullptr); + auto gcrs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(gcrs != nullptr); + EXPECT_EQ(gcrs->exportToJSON((JSONFormatter::create().get())), json); + } + { + auto obj = createFromUserInput(json, DatabaseContext::create()); + auto gcrs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(gcrs != nullptr); + EXPECT_EQ(gcrs->exportToJSON((JSONFormatter::create().get())), + expected_json); + } + { + auto obj = + createFromUserInput(expected_json, DatabaseContext::create()); + auto gcrs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(gcrs != nullptr); + EXPECT_EQ(gcrs->exportToJSON((JSONFormatter::create().get())), + expected_json); + } +} + +// --------------------------------------------------------------------------- + +TEST(json_import, datum_ensemble_without_ellipsoid) { + auto json = "{\n" + " \"type\": \"DatumEnsemble\",\n" + " \"name\": \"ensemble\",\n" + " \"members\": [\n" + " {\n" + " \"name\": \"member1\"\n" + " },\n" + " {\n" + " \"name\": \"member2\"\n" + " }\n" + " ],\n" + " \"accuracy\": \"2\"\n" + "}"; + + // No database + auto obj = createFromUserInput(json, nullptr); + auto ensemble = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(ensemble != nullptr); + EXPECT_EQ(ensemble->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, vertical_crs_with_datum_ensemble) { + auto json = "{\n" + " \"type\": \"VerticalCRS\",\n" + " \"name\": \"foo\",\n" + " \"datum_ensemble\": {\n" + " \"name\": \"ensemble\",\n" + " \"members\": [\n" + " {\n" + " \"name\": \"member1\"\n" + " },\n" + " {\n" + " \"name\": \"member2\"\n" + " }\n" + " ],\n" + " \"accuracy\": \"2\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"vertical\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Gravity-related height\",\n" + " \"abbreviation\": \"H\",\n" + " \"direction\": \"up\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + + // No database + auto obj = createFromUserInput(json, nullptr); + auto vcrs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(vcrs != nullptr); + EXPECT_EQ(vcrs->exportToJSON((JSONFormatter::create().get())), json); +} -- cgit v1.2.3 From 0a1261781de96d2bb8c76fbd905ebf8b0121d3a6 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 10 Aug 2019 17:44:53 +0200 Subject: PROJJSON: a few fixes, and add import of DerivedCRS, EngineeringCRS, ParametricCRS and TemporalCRS --- test/unit/test_io.cpp | 707 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 707 insertions(+) (limited to 'test') diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 67fdcb77..74ef82f3 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -10581,6 +10581,41 @@ TEST(json_import, datum_ensemble_without_ellipsoid) { // --------------------------------------------------------------------------- +TEST(json_import, vertical_crs) { + auto json = "{\n" + " \"type\": \"VerticalCRS\",\n" + " \"name\": \"EGM2008 height\",\n" + " \"datum\": {\n" + " \"type\": \"VerticalReferenceFrame\",\n" + " \"name\": \"EGM2008 geoid\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"vertical\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Gravity-related height\",\n" + " \"abbreviation\": \"H\",\n" + " \"direction\": \"up\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + + auto datum = crs->datum(); + auto datum_json = datum->exportToJSON((JSONFormatter::create().get())); + auto datum_obj = createFromUserInput(datum_json, nullptr); + auto datum_got = nn_dynamic_pointer_cast(datum_obj); + ASSERT_TRUE(datum_got != nullptr); +} + +// --------------------------------------------------------------------------- + TEST(json_import, vertical_crs_with_datum_ensemble) { auto json = "{\n" " \"type\": \"VerticalCRS\",\n" @@ -10616,3 +10651,675 @@ TEST(json_import, vertical_crs_with_datum_ensemble) { ASSERT_TRUE(vcrs != nullptr); EXPECT_EQ(vcrs->exportToJSON((JSONFormatter::create().get())), json); } + +// --------------------------------------------------------------------------- + +TEST(json_import, parametric_crs) { + auto json = "{\n" + " \"type\": \"ParametricCRS\",\n" + " \"name\": \"WMO standard atmosphere layer 0\",\n" + " \"datum\": {\n" + " \"name\": \"Mean Sea Level\",\n" + " \"anchor\": \"1013.25 hPa at 15°C\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"parametric\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Pressure\",\n" + " \"abbreviation\": \"hPa\",\n" + " \"direction\": \"up\",\n" + " \"unit\": {\n" + " \"type\": \"ParametricUnit\",\n" + " \"name\": \"HectoPascal\",\n" + " \"conversion_factor\": 100\n" + " }\n" + " }\n" + " ]\n" + " }\n" + "}"; + + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + + auto datum = crs->datum(); + auto datum_json = datum->exportToJSON((JSONFormatter::create().get())); + auto datum_obj = createFromUserInput(datum_json, nullptr); + auto datum_got = nn_dynamic_pointer_cast(datum_obj); + ASSERT_TRUE(datum_got != nullptr); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, engineering_crs) { + auto json = "{\n" + " \"type\": \"EngineeringCRS\",\n" + " \"name\": \"Engineering CRS\",\n" + " \"datum\": {\n" + " \"name\": \"Engineering datum\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Easting\",\n" + " \"abbreviation\": \"E\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Northing\",\n" + " \"abbreviation\": \"N\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + + auto datum = crs->datum(); + auto datum_json = datum->exportToJSON((JSONFormatter::create().get())); + auto datum_obj = createFromUserInput(datum_json, nullptr); + auto datum_got = nn_dynamic_pointer_cast(datum_obj); + ASSERT_TRUE(datum_got != nullptr); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, temporal_crs) { + auto json = "{\n" + " \"type\": \"TemporalCRS\",\n" + " \"name\": \"Temporal CRS\",\n" + " \"datum\": {\n" + " \"name\": \"Gregorian calendar\",\n" + " \"calendar\": \"proleptic Gregorian\",\n" + " \"time_origin\": \"0000-01-01\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"TemporalDateTime\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Time\",\n" + " \"abbreviation\": \"T\",\n" + " \"direction\": \"future\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + + auto datum = crs->datum(); + auto datum_json = datum->exportToJSON((JSONFormatter::create().get())); + auto datum_obj = createFromUserInput(datum_json, nullptr); + auto datum_got = nn_dynamic_pointer_cast(datum_obj); + ASSERT_TRUE(datum_got != nullptr); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, derived_geodetic_crs) { + auto json = "{\n" + " \"type\": \"DerivedGeodeticCRS\",\n" + " \"name\": \"Derived geodetic CRS\",\n" + " \"base_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Latitude\",\n" + " \"abbreviation\": \"lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Longitude\",\n" + " \"abbreviation\": \"lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"Some conversion\",\n" + " \"method\": {\n" + " \"name\": \"Some method\"\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"foo\",\n" + " \"value\": 1,\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Geocentric X\",\n" + " \"abbreviation\": \"X\",\n" + " \"direction\": \"geocentricX\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Geocentric Y\",\n" + " \"abbreviation\": \"Y\",\n" + " \"direction\": \"geocentricY\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Geocentric Z\",\n" + " \"abbreviation\": \"Z\",\n" + " \"direction\": \"geocentricZ\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, derived_geographic_crs) { + auto json = "{\n" + " \"type\": \"DerivedGeographicCRS\",\n" + " \"name\": \"WMO Atlantic Pole\",\n" + " \"base_crs\": {\n" + " \"type\": \"GeographicCRS\",\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Latitude\",\n" + " \"abbreviation\": \"lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Longitude\",\n" + " \"abbreviation\": \"lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"Atlantic pole\",\n" + " \"method\": {\n" + " \"name\": \"Pole rotation\"\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"Latitude of rotated pole\",\n" + " \"value\": 52,\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Longitude of rotated pole\",\n" + " \"value\": -30,\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Axis rotation\",\n" + " \"value\": -25,\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Latitude\",\n" + " \"abbreviation\": \"lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Longitude\",\n" + " \"abbreviation\": \"lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, derived_projected_crs) { + auto json = "{\n" + " \"type\": \"DerivedProjectedCRS\",\n" + " \"name\": \"derived projectedCRS\",\n" + " \"base_crs\": {\n" + " \"type\": \"ProjectedCRS\",\n" + " \"name\": \"WGS 84 / UTM zone 31N\",\n" + " \"base_crs\": {\n" + " \"name\": \"WGS 84\",\n" + " \"datum\": {\n" + " \"type\": \"GeodeticReferenceFrame\",\n" + " \"name\": \"World Geodetic System 1984\",\n" + " \"ellipsoid\": {\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563\n" + " }\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"ellipsoidal\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Latitude\",\n" + " \"abbreviation\": \"lat\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"degree\"\n" + " },\n" + " {\n" + " \"name\": \"Longitude\",\n" + " \"abbreviation\": \"lon\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"degree\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"UTM zone 31N\",\n" + " \"method\": {\n" + " \"name\": \"Transverse Mercator\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 9807\n" + " }\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"Latitude of natural origin\",\n" + " \"value\": 0,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8801\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Longitude of natural origin\",\n" + " \"value\": 3,\n" + " \"unit\": \"degree\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8802\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"Scale factor at natural origin\",\n" + " \"value\": 0.9996,\n" + " \"unit\": \"unity\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8805\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"False easting\",\n" + " \"value\": 500000,\n" + " \"unit\": \"metre\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8806\n" + " }\n" + " },\n" + " {\n" + " \"name\": \"False northing\",\n" + " \"value\": 0,\n" + " \"unit\": \"metre\",\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8807\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Easting\",\n" + " \"abbreviation\": \"E\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Northing\",\n" + " \"abbreviation\": \"N\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"unnamed\",\n" + " \"method\": {\n" + " \"name\": \"PROJ unimplemented\"\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"foo\",\n" + " \"value\": 1,\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Easting\",\n" + " \"abbreviation\": \"E\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Northing\",\n" + " \"abbreviation\": \"N\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, derived_vertical_crs) { + auto json = "{\n" + " \"type\": \"DerivedVerticalCRS\",\n" + " \"name\": \"Derived vertCRS\",\n" + " \"base_crs\": {\n" + " \"type\": \"VerticalCRS\",\n" + " \"name\": \"ODN height\",\n" + " \"datum\": {\n" + " \"type\": \"VerticalReferenceFrame\",\n" + " \"name\": \"Ordnance Datum Newlyn\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"vertical\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Gravity-related height\",\n" + " \"abbreviation\": \"H\",\n" + " \"direction\": \"up\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"unnamed\",\n" + " \"method\": {\n" + " \"name\": \"PROJ unimplemented\"\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"foo\",\n" + " \"value\": 1,\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"vertical\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Gravity-related height\",\n" + " \"abbreviation\": \"H\",\n" + " \"direction\": \"up\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, derived_engineering_crs) { + auto json = "{\n" + " \"type\": \"DerivedEngineeringCRS\",\n" + " \"name\": \"Derived EngineeringCRS\",\n" + " \"base_crs\": {\n" + " \"type\": \"EngineeringCRS\",\n" + " \"name\": \"Engineering CRS\",\n" + " \"datum\": {\n" + " \"name\": \"Engineering datum\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Easting\",\n" + " \"abbreviation\": \"E\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Northing\",\n" + " \"abbreviation\": \"N\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"unnamed\",\n" + " \"method\": {\n" + " \"name\": \"PROJ unimplemented\"\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"foo\",\n" + " \"value\": 1,\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"Cartesian\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Easting\",\n" + " \"abbreviation\": \"E\",\n" + " \"direction\": \"east\",\n" + " \"unit\": \"metre\"\n" + " },\n" + " {\n" + " \"name\": \"Northing\",\n" + " \"abbreviation\": \"N\",\n" + " \"direction\": \"north\",\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, derived_parametric_crs) { + auto json = "{\n" + " \"type\": \"DerivedParametricCRS\",\n" + " \"name\": \"Derived ParametricCRS\",\n" + " \"base_crs\": {\n" + " \"type\": \"ParametricCRS\",\n" + " \"name\": \"Parametric CRS\",\n" + " \"datum\": {\n" + " \"name\": \"Parametric datum\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"parametric\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"unknown parametric\",\n" + " \"abbreviation\": \"\",\n" + " \"direction\": \"unspecified\",\n" + " \"unit\": {\n" + " \"type\": \"ParametricUnit\",\n" + " \"name\": \"unknown\",\n" + " \"conversion_factor\": 1\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"unnamed\",\n" + " \"method\": {\n" + " \"name\": \"PROJ unimplemented\"\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"foo\",\n" + " \"value\": 1,\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"parametric\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Pressure\",\n" + " \"abbreviation\": \"hPa\",\n" + " \"direction\": \"up\",\n" + " \"unit\": {\n" + " \"type\": \"ParametricUnit\",\n" + " \"name\": \"HectoPascal\",\n" + " \"conversion_factor\": 100\n" + " }\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); +} + +// --------------------------------------------------------------------------- + +TEST(json_import, derived_temporal_crs) { + auto json = "{\n" + " \"type\": \"DerivedTemporalCRS\",\n" + " \"name\": \"Derived TemporalCRS\",\n" + " \"base_crs\": {\n" + " \"type\": \"TemporalCRS\",\n" + " \"name\": \"Temporal CRS\",\n" + " \"datum\": {\n" + " \"name\": \"Gregorian calendar\",\n" + " \"calendar\": \"proleptic Gregorian\",\n" + " \"time_origin\": \"0000-01-01\"\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"TemporalDateTime\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"unknown temporal\",\n" + " \"abbreviation\": \"\",\n" + " \"direction\": \"future\",\n" + " \"unit\": {\n" + " \"type\": \"TimeUnit\",\n" + " \"name\": \"unknown\",\n" + " \"conversion_factor\": 1\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " },\n" + " \"conversion\": {\n" + " \"name\": \"unnamed\",\n" + " \"method\": {\n" + " \"name\": \"PROJ unimplemented\"\n" + " },\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"foo\",\n" + " \"value\": 1,\n" + " \"unit\": \"metre\"\n" + " }\n" + " ]\n" + " },\n" + " \"coordinate_system\": {\n" + " \"subtype\": \"TemporalDateTime\",\n" + " \"axis\": [\n" + " {\n" + " \"name\": \"Time\",\n" + " \"abbreviation\": \"T\",\n" + " \"direction\": \"future\"\n" + " }\n" + " ]\n" + " }\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); +} -- cgit v1.2.3 From 8d0500b325d12b047797a60e3c13d4b473fae987 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 12 Aug 2019 13:45:17 +0200 Subject: PROJJSON: add support for importing 'ids' --- test/unit/test_io.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test') diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 74ef82f3..e1d424e9 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -11323,3 +11323,28 @@ TEST(json_import, derived_temporal_crs) { ASSERT_TRUE(crs != nullptr); EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); } + +// --------------------------------------------------------------------------- + +TEST(json_import, multiple_ids) { + auto json = "{\n" + " \"type\": \"Ellipsoid\",\n" + " \"name\": \"WGS 84\",\n" + " \"semi_major_axis\": 6378137,\n" + " \"inverse_flattening\": 298.257223563,\n" + " \"ids\": [\n" + " {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 4326\n" + " },\n" + " {\n" + " \"authority\": \"FOO\",\n" + " \"code\": \"BAR\"\n" + " }\n" + " ]\n" + "}"; + auto obj = createFromUserInput(json, nullptr); + auto ellps = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(ellps != nullptr); + EXPECT_EQ(ellps->exportToJSON((JSONFormatter::create().get())), json); +} -- cgit v1.2.3 From cad1c5cf61fc00759bf4ad17b0b34f57f4945de6 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 17 Aug 2019 10:58:08 +0200 Subject: PROJJSON: rename file as projjson.schema.json, and add versionning to it and to exported PROJJSON strings --- test/cli/testprojinfo_out.dist | 1 + test/unit/test_c_api.cpp | 7 +- test/unit/test_datum.cpp | 27 ++++---- test/unit/test_io.cpp | 153 ++++++++++++++++++++++++++++++----------- 4 files changed, 134 insertions(+), 54 deletions(-) (limited to 'test') diff --git a/test/cli/testprojinfo_out.dist b/test/cli/testprojinfo_out.dist index 73751b99..97c1138c 100644 --- a/test/cli/testprojinfo_out.dist +++ b/test/cli/testprojinfo_out.dist @@ -137,6 +137,7 @@ GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.25722 PROJJSON: { + "$schema": "https://proj.org/schemas/v0.1/projjson.schema.json", "type": "GeographicCRS", "name": "WGS 84", "datum": { diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index 5649ca9f..97440796 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -3503,6 +3503,8 @@ TEST_F(CApi, proj_as_projjson) { ASSERT_NE(projjson, nullptr); EXPECT_EQ(std::string(projjson), "{\n" + " \"$schema\": " + "\"https://proj.org/schemas/v0.1/projjson.schema.json\",\n" " \"type\": \"Ellipsoid\",\n" " \"name\": \"WGS 84\",\n" " \"semi_major_axis\": 6378137,\n" @@ -3514,7 +3516,8 @@ TEST_F(CApi, proj_as_projjson) { "}"); } { - const char *const options[] = {"INDENTATION_WIDTH=4", nullptr}; + const char *const options[] = {"INDENTATION_WIDTH=4", "SCHEMA=", + nullptr}; auto projjson = proj_as_projjson(m_ctxt, obj, options); ASSERT_NE(projjson, nullptr); EXPECT_EQ(std::string(projjson), @@ -3530,7 +3533,7 @@ TEST_F(CApi, proj_as_projjson) { "}"); } { - const char *const options[] = {"MULTILINE=NO", nullptr}; + const char *const options[] = {"MULTILINE=NO", "SCHEMA=", nullptr}; auto projjson = proj_as_projjson(m_ctxt, obj, options); ASSERT_NE(projjson, nullptr); EXPECT_EQ(std::string(projjson), diff --git a/test/unit/test_datum.cpp b/test/unit/test_datum.cpp index d8fab1f0..fbd1f79d 100644 --- a/test/unit/test_datum.cpp +++ b/test/unit/test_datum.cpp @@ -207,19 +207,20 @@ TEST(datum, prime_meridian_to_PROJString) { TEST(datum, prime_meridian_to_JSON) { - EXPECT_EQ( - PrimeMeridian::GREENWICH->exportToJSON(JSONFormatter::create().get()), - "{\n" - " \"type\": \"PrimeMeridian\",\n" - " \"name\": \"Greenwich\",\n" - " \"longitude\": 0,\n" - " \"id\": {\n" - " \"authority\": \"EPSG\",\n" - " \"code\": 8901\n" - " }\n" - "}"); - - EXPECT_EQ(PrimeMeridian::PARIS->exportToJSON(JSONFormatter::create().get()), + EXPECT_EQ(PrimeMeridian::GREENWICH->exportToJSON( + &(JSONFormatter::create()->setSchema(""))), + "{\n" + " \"type\": \"PrimeMeridian\",\n" + " \"name\": \"Greenwich\",\n" + " \"longitude\": 0,\n" + " \"id\": {\n" + " \"authority\": \"EPSG\",\n" + " \"code\": 8901\n" + " }\n" + "}"); + + EXPECT_EQ(PrimeMeridian::PARIS->exportToJSON( + &(JSONFormatter::create()->setSchema(""))), "{\n" " \"type\": \"PrimeMeridian\",\n" " \"name\": \"Paris\",\n" diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index e1d424e9..7a3e6729 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -9137,6 +9137,7 @@ TEST(wkt_export, invalid_angular_unit) { TEST(json_import, ellipsoid_flattened_sphere) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"Ellipsoid\",\n" " \"name\": \"WGS 84\",\n" " \"semi_major_axis\": 6378137,\n" @@ -9149,13 +9150,15 @@ TEST(json_import, ellipsoid_flattened_sphere) { auto obj = createFromUserInput(json, nullptr); auto ellps = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(ellps != nullptr); - EXPECT_EQ(ellps->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(ellps->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, ellipsoid_major_minor_custom_unit) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"Ellipsoid\",\n" " \"name\": \"foo\",\n" " \"semi_major_axis\": 6378137,\n" @@ -9171,13 +9174,15 @@ TEST(json_import, ellipsoid_major_minor_custom_unit) { auto obj = createFromUserInput(json, nullptr); auto ellps = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(ellps != nullptr); - EXPECT_EQ(ellps->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(ellps->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, ellipsoid_sphere) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"Ellipsoid\",\n" " \"name\": \"Sphere\",\n" " \"radius\": 6371000,\n" @@ -9189,7 +9194,8 @@ TEST(json_import, ellipsoid_sphere) { auto obj = createFromUserInput(json, nullptr); auto ellps = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(ellps != nullptr); - EXPECT_EQ(ellps->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(ellps->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- @@ -9217,6 +9223,7 @@ TEST(json_import, ellipsoid_errors) { TEST(json_import, prime_meridian) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"PrimeMeridian\",\n" " \"name\": \"Paris\",\n" " \"longitude\": {\n" @@ -9231,7 +9238,8 @@ TEST(json_import, prime_meridian) { auto obj = createFromUserInput(json, nullptr); auto pm = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(pm != nullptr); - EXPECT_EQ(pm->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(pm->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- @@ -9251,6 +9259,7 @@ TEST(json_import, prime_meridian_errors) { TEST(json_import, geodetic_reference_frame_with_implicit_prime_meridian) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"GeodeticReferenceFrame\",\n" " \"name\": \"World Geodetic System 1984\",\n" " \"ellipsoid\": {\n" @@ -9262,13 +9271,15 @@ TEST(json_import, geodetic_reference_frame_with_implicit_prime_meridian) { auto obj = createFromUserInput(json, nullptr); auto grf = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(grf != nullptr); - EXPECT_EQ(grf->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(grf->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, geodetic_reference_frame_with_explicit_prime_meridian) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"GeodeticReferenceFrame\",\n" " \"name\": \"Nouvelle Triangulation Francaise (Paris)\",\n" " \"ellipsoid\": {\n" @@ -9291,7 +9302,8 @@ TEST(json_import, geodetic_reference_frame_with_explicit_prime_meridian) { auto obj = createFromUserInput(json, nullptr); auto grf = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(grf != nullptr); - EXPECT_EQ(grf->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(grf->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- @@ -9299,6 +9311,7 @@ TEST(json_import, geodetic_reference_frame_with_explicit_prime_meridian) { TEST(json_import, dynamic_geodetic_reference_frame_with_implicit_prime_meridian) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DynamicGeodeticReferenceFrame\",\n" " \"name\": \"World Geodetic System 1984\",\n" " \"frame_reference_epoch\": 1,\n" @@ -9312,7 +9325,8 @@ TEST(json_import, auto obj = createFromUserInput(json, nullptr); auto dgrf = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(dgrf != nullptr); - EXPECT_EQ(dgrf->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(dgrf->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- @@ -9329,6 +9343,7 @@ TEST(json_import, geodetic_reference_frame_errors) { TEST(json_import, dynamic_vertical_reference_frame) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DynamicVerticalReferenceFrame\",\n" " \"name\": \"bar\",\n" " \"frame_reference_epoch\": 1,\n" @@ -9337,13 +9352,15 @@ TEST(json_import, dynamic_vertical_reference_frame) { auto obj = createFromUserInput(json, nullptr); auto dvrf = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(dvrf != nullptr); - EXPECT_EQ(dvrf->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(dvrf->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, several_usages) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"GeodeticReferenceFrame\",\n" " \"name\": \"World Geodetic System 1984\",\n" " \"ellipsoid\": {\n" @@ -9370,13 +9387,15 @@ TEST(json_import, several_usages) { auto obj = createFromUserInput(json, nullptr); auto gdr = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(gdr != nullptr); - EXPECT_EQ(gdr->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(gdr->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, geographic_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"GeographicCRS\",\n" " \"name\": \"WGS 84\",\n" " \"datum\": {\n" @@ -9421,7 +9440,8 @@ TEST(json_import, geographic_crs) { auto obj = createFromUserInput(json, nullptr); auto gcrs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(gcrs != nullptr); - EXPECT_EQ(gcrs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(gcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- @@ -9486,6 +9506,7 @@ TEST(json_import, geographic_crs_errors) { TEST(json_import, geocentric_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"GeodeticCRS\",\n" " \"name\": \"WGS 84\",\n" " \"datum\": {\n" @@ -9524,13 +9545,15 @@ TEST(json_import, geocentric_crs) { auto obj = createFromUserInput(json, nullptr); auto gdcrs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(gdcrs != nullptr); - EXPECT_EQ(gdcrs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(gdcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, projected_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"ProjectedCRS\",\n" " \"name\": \"WGS 84 / UTM zone 31N\",\n" " \"base_crs\": {\n" @@ -9644,13 +9667,15 @@ TEST(json_import, projected_crs) { auto obj = createFromUserInput(json, nullptr); auto pcrs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(pcrs != nullptr); - EXPECT_EQ(pcrs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(pcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, compound_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"CompoundCRS\",\n" " \"name\": \"WGS 84 + EGM2008 height\",\n" " \"components\": [\n" @@ -9716,7 +9741,9 @@ TEST(json_import, compound_crs) { auto obj = createFromUserInput(json, nullptr); auto compoundCRS = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(compoundCRS != nullptr); - EXPECT_EQ(compoundCRS->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ( + compoundCRS->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- @@ -9724,6 +9751,7 @@ TEST(json_import, compound_crs) { TEST(json_import, bound_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"BoundCRS\",\n" " \"source_crs\": {\n" " \"type\": \"GeographicCRS\",\n" @@ -9817,13 +9845,16 @@ TEST(json_import, bound_crs) { auto obj = createFromUserInput(json, nullptr); auto boundCRS = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(boundCRS != nullptr); - EXPECT_EQ(boundCRS->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ( + boundCRS->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, transformation) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"Transformation\",\n" " \"name\": \"GDA94 to GDA2020 (1)\",\n" " \"source_crs\": {\n" @@ -10004,7 +10035,9 @@ TEST(json_import, transformation) { auto obj = createFromUserInput(json, nullptr); auto transf = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(transf != nullptr); - EXPECT_EQ(transf->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ( + transf->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- @@ -10012,6 +10045,7 @@ TEST(json_import, transformation) { TEST(json_import, concatenated_operation) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"ConcatenatedOperation\",\n" " \"name\": \"Inverse of Vicgrid + GDA94 to GDA2020 (1)\",\n" " \"source_crs\": {\n" @@ -10434,13 +10468,16 @@ TEST(json_import, concatenated_operation) { auto obj = createFromUserInput(json, nullptr); auto concat = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(concat != nullptr); - EXPECT_EQ(concat->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ( + concat->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, geographic_crs_with_datum_ensemble) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"GeographicCRS\",\n" " \"name\": \"WGS 84\",\n" " \"datum_ensemble\": {\n" @@ -10481,6 +10518,7 @@ TEST(json_import, geographic_crs_with_datum_ensemble) { auto expected_json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"GeographicCRS\",\n" " \"name\": \"WGS 84\",\n" " \"datum_ensemble\": {\n" @@ -10536,22 +10574,26 @@ TEST(json_import, geographic_crs_with_datum_ensemble) { auto obj = createFromUserInput(json, nullptr); auto gcrs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(gcrs != nullptr); - EXPECT_EQ(gcrs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ( + gcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } { auto obj = createFromUserInput(json, DatabaseContext::create()); auto gcrs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(gcrs != nullptr); - EXPECT_EQ(gcrs->exportToJSON((JSONFormatter::create().get())), - expected_json); + EXPECT_EQ( + gcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + expected_json); } { auto obj = createFromUserInput(expected_json, DatabaseContext::create()); auto gcrs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(gcrs != nullptr); - EXPECT_EQ(gcrs->exportToJSON((JSONFormatter::create().get())), - expected_json); + EXPECT_EQ( + gcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + expected_json); } } @@ -10559,6 +10601,7 @@ TEST(json_import, geographic_crs_with_datum_ensemble) { TEST(json_import, datum_ensemble_without_ellipsoid) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DatumEnsemble\",\n" " \"name\": \"ensemble\",\n" " \"members\": [\n" @@ -10576,13 +10619,16 @@ TEST(json_import, datum_ensemble_without_ellipsoid) { auto obj = createFromUserInput(json, nullptr); auto ensemble = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(ensemble != nullptr); - EXPECT_EQ(ensemble->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ( + ensemble->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, vertical_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"VerticalCRS\",\n" " \"name\": \"EGM2008 height\",\n" " \"datum\": {\n" @@ -10605,10 +10651,12 @@ TEST(json_import, vertical_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); auto datum = crs->datum(); - auto datum_json = datum->exportToJSON((JSONFormatter::create().get())); + auto datum_json = + datum->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))); auto datum_obj = createFromUserInput(datum_json, nullptr); auto datum_got = nn_dynamic_pointer_cast(datum_obj); ASSERT_TRUE(datum_got != nullptr); @@ -10618,6 +10666,7 @@ TEST(json_import, vertical_crs) { TEST(json_import, vertical_crs_with_datum_ensemble) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"VerticalCRS\",\n" " \"name\": \"foo\",\n" " \"datum_ensemble\": {\n" @@ -10649,13 +10698,15 @@ TEST(json_import, vertical_crs_with_datum_ensemble) { auto obj = createFromUserInput(json, nullptr); auto vcrs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(vcrs != nullptr); - EXPECT_EQ(vcrs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(vcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, parametric_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"ParametricCRS\",\n" " \"name\": \"WMO standard atmosphere layer 0\",\n" " \"datum\": {\n" @@ -10682,10 +10733,12 @@ TEST(json_import, parametric_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); auto datum = crs->datum(); - auto datum_json = datum->exportToJSON((JSONFormatter::create().get())); + auto datum_json = + datum->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))); auto datum_obj = createFromUserInput(datum_json, nullptr); auto datum_got = nn_dynamic_pointer_cast(datum_obj); ASSERT_TRUE(datum_got != nullptr); @@ -10695,6 +10748,7 @@ TEST(json_import, parametric_crs) { TEST(json_import, engineering_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"EngineeringCRS\",\n" " \"name\": \"Engineering CRS\",\n" " \"datum\": {\n" @@ -10722,10 +10776,12 @@ TEST(json_import, engineering_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); auto datum = crs->datum(); - auto datum_json = datum->exportToJSON((JSONFormatter::create().get())); + auto datum_json = + datum->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))); auto datum_obj = createFromUserInput(datum_json, nullptr); auto datum_got = nn_dynamic_pointer_cast(datum_obj); ASSERT_TRUE(datum_got != nullptr); @@ -10735,6 +10791,7 @@ TEST(json_import, engineering_crs) { TEST(json_import, temporal_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"TemporalCRS\",\n" " \"name\": \"Temporal CRS\",\n" " \"datum\": {\n" @@ -10757,10 +10814,12 @@ TEST(json_import, temporal_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); auto datum = crs->datum(); - auto datum_json = datum->exportToJSON((JSONFormatter::create().get())); + auto datum_json = + datum->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))); auto datum_obj = createFromUserInput(datum_json, nullptr); auto datum_got = nn_dynamic_pointer_cast(datum_obj); ASSERT_TRUE(datum_got != nullptr); @@ -10770,6 +10829,7 @@ TEST(json_import, temporal_crs) { TEST(json_import, derived_geodetic_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DerivedGeodeticCRS\",\n" " \"name\": \"Derived geodetic CRS\",\n" " \"base_crs\": {\n" @@ -10842,13 +10902,15 @@ TEST(json_import, derived_geodetic_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, derived_geographic_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DerivedGeographicCRS\",\n" " \"name\": \"WMO Atlantic Pole\",\n" " \"base_crs\": {\n" @@ -10925,13 +10987,15 @@ TEST(json_import, derived_geographic_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, derived_projected_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DerivedProjectedCRS\",\n" " \"name\": \"derived projectedCRS\",\n" " \"base_crs\": {\n" @@ -11075,13 +11139,15 @@ TEST(json_import, derived_projected_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, derived_vertical_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DerivedVerticalCRS\",\n" " \"name\": \"Derived vertCRS\",\n" " \"base_crs\": {\n" @@ -11131,13 +11197,15 @@ TEST(json_import, derived_vertical_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, derived_engineering_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DerivedEngineeringCRS\",\n" " \"name\": \"Derived EngineeringCRS\",\n" " \"base_crs\": {\n" @@ -11198,13 +11266,15 @@ TEST(json_import, derived_engineering_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, derived_parametric_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DerivedParametricCRS\",\n" " \"name\": \"Derived ParametricCRS\",\n" " \"base_crs\": {\n" @@ -11261,13 +11331,15 @@ TEST(json_import, derived_parametric_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, derived_temporal_crs) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"DerivedTemporalCRS\",\n" " \"name\": \"Derived TemporalCRS\",\n" " \"base_crs\": {\n" @@ -11321,13 +11393,15 @@ TEST(json_import, derived_temporal_crs) { auto obj = createFromUserInput(json, nullptr); auto crs = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(crs != nullptr); - EXPECT_EQ(crs->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(crs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } // --------------------------------------------------------------------------- TEST(json_import, multiple_ids) { auto json = "{\n" + " \"$schema\": \"foo\",\n" " \"type\": \"Ellipsoid\",\n" " \"name\": \"WGS 84\",\n" " \"semi_major_axis\": 6378137,\n" @@ -11346,5 +11420,6 @@ TEST(json_import, multiple_ids) { auto obj = createFromUserInput(json, nullptr); auto ellps = nn_dynamic_pointer_cast(obj); ASSERT_TRUE(ellps != nullptr); - EXPECT_EQ(ellps->exportToJSON((JSONFormatter::create().get())), json); + EXPECT_EQ(ellps->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))), + json); } -- cgit v1.2.3