From 5163741254088b7f3fbb651349463cd2942df4f6 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 10 Oct 2020 14:23:42 +0200 Subject: WKT2:2019 import/export: handle DATUM (at top level object) with PRIMEM This is a peculiarity of the WKT grammar. Despite ISO 19111 saying that the prime meridian is a component of the datum, in WKT, they are placed at the same level, for backward compatibility with earlier WKT versions. So handle exporting and importing that. The fix is only for situation where DATUM is the top level object (was working fine otherwise), which is a uncommon use case. And to limit the amount of issue, on export emit the prime meridian only if it is not Greenwich. --- test/unit/test_io.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/unit/test_io.cpp') diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 34396fcf..47e574c5 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -190,6 +190,28 @@ TEST(wkt_parse, datum_with_ANCHOR) { // --------------------------------------------------------------------------- +TEST(wkt_parse, datum_with_pm) { + const char *wkt = + "DATUM[\"Nouvelle Triangulation Francaise (Paris)\",\n" + " ELLIPSOID[\"Clarke 1880 (IGN)\",6378249.2,293.466021293627,\n" + " LENGTHUNIT[\"metre\",1]],\n" + " ID[\"EPSG\",6807]],\n" + "PRIMEM[\"Paris\",2.5969213,\n" + " ANGLEUNIT[\"grad\",0.0157079632679489],\n" + " ID[\"EPSG\",8903]]"; + + auto obj = WKTParser().createFromWKT(wkt); + auto datum = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(datum != nullptr); + EXPECT_EQ(datum->primeMeridian()->nameStr(), "Paris"); + EXPECT_EQ( + datum->exportToWKT( + WKTFormatter::create(WKTFormatter::Convention::WKT2_2019).get()), + wkt); +} + +// --------------------------------------------------------------------------- + TEST(wkt_parse, datum_no_pm_not_earth) { auto obj = WKTParser().createFromWKT("DATUM[\"unnamed\",\n" " ELLIPSOID[\"unnamed\",1,0,\n" -- cgit v1.2.3