diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-12-04 16:22:44 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-12-04 17:05:32 +0100 |
| commit | 57b00a63c6caee1a53961d542904f7c9b1f014c9 (patch) | |
| tree | 599ca27d29cda4519687ca324f96b2662ba456f9 | |
| parent | d06c1c55c1c3fc7209abdbdfbf2e3cf34f18cf98 (diff) | |
| download | PROJ-57b00a63c6caee1a53961d542904f7c9b1f014c9.tar.gz PROJ-57b00a63c6caee1a53961d542904f7c9b1f014c9.zip | |
Improve management of 'deprecated' suffix in object names
| -rw-r--r-- | src/c_api.cpp | 11 | ||||
| -rw-r--r-- | src/crs.cpp | 49 | ||||
| -rw-r--r-- | src/io.cpp | 4 | ||||
| -rw-r--r-- | test/unit/test_c_api.cpp | 76 | ||||
| -rw-r--r-- | test/unit/test_io.cpp | 23 |
5 files changed, 126 insertions, 37 deletions
diff --git a/src/c_api.cpp b/src/c_api.cpp index 5c873dcf..718d46bf 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -1805,9 +1805,14 @@ PJ_OBJ *proj_obj_crs_get_coordoperation(PJ_CONTEXT *ctx, const PJ_OBJ *crs, // --------------------------------------------------------------------------- //! @cond Doxygen_Suppress -static PropertyMap createPropertyMapName(const char *name) { - return PropertyMap().set(common::IdentifiedObject::NAME_KEY, - name ? name : "unnamed"); +static PropertyMap createPropertyMapName(const char *c_name) { + std::string name(c_name ? c_name : "unnamed"); + PropertyMap properties; + if (ends_with(name, " (deprecated)")) { + name.resize(name.size() - strlen(" (deprecated)")); + properties.set(common::IdentifiedObject::DEPRECATED_KEY, true); + } + return properties.set(common::IdentifiedObject::NAME_KEY, name); } // --------------------------------------------------------------------------- diff --git a/src/crs.cpp b/src/crs.cpp index 31682644..d4d98fa4 100644 --- a/src/crs.cpp +++ b/src/crs.cpp @@ -213,9 +213,16 @@ GeographicCRSPtr CRS::extractGeographicCRS() const { // --------------------------------------------------------------------------- //! @cond Doxygen_Suppress -static util::PropertyMap createPropertyMapName(const std::string &name) { - return util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, name); +static util::PropertyMap +createPropertyMap(const common::IdentifiedObject *obj) { + auto props = util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, + obj->nameStr()); + if (obj->isDeprecated()) { + props.set(common::IdentifiedObject::DEPRECATED_KEY, true); + } + return props; } + //! @endcond // --------------------------------------------------------------------------- @@ -229,9 +236,9 @@ CRSNNPtr CRS::alterGeodeticCRS(const GeodeticCRSNNPtr &newGeodCRS) const { auto projCRS = dynamic_cast<const ProjectedCRS *>(this); if (projCRS) { - return ProjectedCRS::create( - createPropertyMapName(nameStr()), newGeodCRS, - projCRS->derivingConversionRef(), projCRS->coordinateSystem()); + return ProjectedCRS::create(createPropertyMap(this), newGeodCRS, + projCRS->derivingConversionRef(), + projCRS->coordinateSystem()); } auto compoundCRS = dynamic_cast<const CompoundCRS *>(this); @@ -240,8 +247,7 @@ CRSNNPtr CRS::alterGeodeticCRS(const GeodeticCRSNNPtr &newGeodCRS) const { for (const auto &subCrs : compoundCRS->componentReferenceSystems()) { components.emplace_back(subCrs->alterGeodeticCRS(newGeodCRS)); } - return CompoundCRS::create(createPropertyMapName(nameStr()), - components); + return CompoundCRS::create(createPropertyMap(this), components); } return NN_NO_CHECK( @@ -257,8 +263,8 @@ CRSNNPtr CRS::alterCSLinearUnit(const common::UnitOfMeasure &unit) const { auto projCRS = dynamic_cast<const ProjectedCRS *>(this); if (projCRS) { return ProjectedCRS::create( - createPropertyMapName(projCRS->nameStr().c_str()), - projCRS->baseCRS(), projCRS->derivingConversionRef(), + createPropertyMap(this), projCRS->baseCRS(), + projCRS->derivingConversionRef(), projCRS->coordinateSystem()->alterUnit(unit)); } } @@ -270,9 +276,8 @@ CRSNNPtr CRS::alterCSLinearUnit(const common::UnitOfMeasure &unit) const { geodCRS->coordinateSystem().get()); assert(cs); return GeodeticCRS::create( - createPropertyMapName(geodCRS->nameStr().c_str()), - geodCRS->datum(), geodCRS->datumEnsemble(), - cs->alterUnit(unit)); + createPropertyMap(this), geodCRS->datum(), + geodCRS->datumEnsemble(), cs->alterUnit(unit)); } } @@ -280,8 +285,8 @@ CRSNNPtr CRS::alterCSLinearUnit(const common::UnitOfMeasure &unit) const { auto geogCRS = dynamic_cast<const GeographicCRS *>(this); if (geogCRS && geogCRS->coordinateSystem()->axisList().size() == 3) { return GeographicCRS::create( - createPropertyMapName(geogCRS->nameStr().c_str()), - geogCRS->datum(), geogCRS->datumEnsemble(), + createPropertyMap(this), geogCRS->datum(), + geogCRS->datumEnsemble(), geogCRS->coordinateSystem()->alterLinearUnit(unit)); } } @@ -290,8 +295,8 @@ CRSNNPtr CRS::alterCSLinearUnit(const common::UnitOfMeasure &unit) const { auto vertCRS = dynamic_cast<const VerticalCRS *>(this); if (vertCRS) { return VerticalCRS::create( - createPropertyMapName(vertCRS->nameStr().c_str()), - vertCRS->datum(), vertCRS->datumEnsemble(), + createPropertyMap(this), vertCRS->datum(), + vertCRS->datumEnsemble(), vertCRS->coordinateSystem()->alterUnit(unit)); } } @@ -501,8 +506,14 @@ CRSNNPtr CRS::shallowClone() const { return _shallowClone(); } CRSNNPtr CRS::alterName(const std::string &newName) const { auto crs = shallowClone(); - crs->setProperties( - util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, newName)); + auto newNameMod(newName); + auto props = util::PropertyMap(); + if (ends_with(newNameMod, " (deprecated)")) { + newNameMod.resize(newNameMod.size() - strlen(" (deprecated)")); + props.set(common::IdentifiedObject::DEPRECATED_KEY, true); + } + props.set(common::IdentifiedObject::NAME_KEY, newNameMod); + crs->setProperties(props); return crs; } @@ -2671,7 +2682,7 @@ bool ProjectedCRS::_isEquivalentTo( ProjectedCRSNNPtr ProjectedCRS::alterParametersLinearUnit(const common::UnitOfMeasure &unit, bool convertToNewUnit) const { - return create(createPropertyMapName(nameStr()), baseCRS(), + return create(createPropertyMap(this), baseCRS(), derivingConversionRef()->alterParametersLinearUnit( unit, convertToNewUnit), coordinateSystem()); @@ -1449,6 +1449,10 @@ PropertyMap &WKTParser::Private::buildProperties(const WKTNodeNNPtr &node) { if (!nodeChildren.empty()) { const auto &nodeName(nodeP->value()); auto name(stripQuotes(nodeChildren[0])); + if (ends_with(name, " (deprecated)")) { + name.resize(name.size() - strlen(" (deprecated)")); + properties->set(common::IdentifiedObject::DEPRECATED_KEY, true); + } const char *tableNameForAlias = nullptr; if (ci_equal(nodeName, WKTConstants::GEOGCS)) { diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index f0480ebe..bec965ce 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -1625,6 +1625,21 @@ TEST_F(CApi, proj_obj_create_geographic_crs) { std::string("System of the Unified Trigonometrical Cadastral " "Network (Ferro)")); } + + // WKT1 with (deprecated) + { + auto crs = proj_obj_create_geographic_crs( + m_ctxt, "SAD69 (deprecated)", "South_American_Datum_1969", + "GRS 1967", 6378160, 298.247167427, "Greenwich", 0, "Degree", + 0.0174532925199433, cs); + ObjectKeeper keeper(crs); + ASSERT_NE(crs, nullptr); + + auto name = proj_obj_get_name(crs); + ASSERT_TRUE(name != nullptr); + EXPECT_EQ(name, std::string("SAD69")); + EXPECT_TRUE(proj_obj_is_deprecated(crs)); + } } // --------------------------------------------------------------------------- @@ -2199,20 +2214,38 @@ TEST_F(CApi, proj_obj_crs_alter_geodetic_crs) { EXPECT_TRUE( proj_obj_is_equivalent_to(geodCRSAltered, newGeodCRS, PJ_COMP_STRICT)); - auto projCRSAltered = - proj_obj_crs_alter_geodetic_crs(m_ctxt, projCRS, newGeodCRS); - ObjectKeeper keeper_projCRSAltered(projCRSAltered); - ASSERT_NE(projCRSAltered, nullptr); + { + auto projCRSAltered = + proj_obj_crs_alter_geodetic_crs(m_ctxt, projCRS, newGeodCRS); + ObjectKeeper keeper_projCRSAltered(projCRSAltered); + ASSERT_NE(projCRSAltered, nullptr); - EXPECT_EQ(proj_obj_get_type(projCRSAltered), PJ_OBJ_TYPE_PROJECTED_CRS); + EXPECT_EQ(proj_obj_get_type(projCRSAltered), PJ_OBJ_TYPE_PROJECTED_CRS); - auto projCRSAltered_geodCRS = - proj_obj_crs_get_geodetic_crs(m_ctxt, projCRSAltered); - ObjectKeeper keeper_projCRSAltered_geodCRS(projCRSAltered_geodCRS); - ASSERT_NE(projCRSAltered_geodCRS, nullptr); + auto projCRSAltered_geodCRS = + proj_obj_crs_get_geodetic_crs(m_ctxt, projCRSAltered); + ObjectKeeper keeper_projCRSAltered_geodCRS(projCRSAltered_geodCRS); + ASSERT_NE(projCRSAltered_geodCRS, nullptr); + + EXPECT_TRUE(proj_obj_is_equivalent_to(projCRSAltered_geodCRS, + newGeodCRS, PJ_COMP_STRICT)); + } - EXPECT_TRUE(proj_obj_is_equivalent_to(projCRSAltered_geodCRS, newGeodCRS, - PJ_COMP_STRICT)); + // Check that proj_obj_crs_alter_geodetic_crs preserves deprecation flag + { + auto projCRSDeprecated = + proj_obj_alter_name(m_ctxt, projCRS, "new name (deprecated)"); + ObjectKeeper keeper_projCRSDeprecated(projCRSDeprecated); + ASSERT_NE(projCRSDeprecated, nullptr); + + auto projCRSAltered = proj_obj_crs_alter_geodetic_crs( + m_ctxt, projCRSDeprecated, newGeodCRS); + ObjectKeeper keeper_projCRSAltered(projCRSAltered); + ASSERT_NE(projCRSAltered, nullptr); + + EXPECT_EQ(proj_obj_get_name(projCRSAltered), std::string("new name")); + EXPECT_TRUE(proj_obj_is_deprecated(projCRSAltered)); + } } // --------------------------------------------------------------------------- @@ -2338,11 +2371,24 @@ TEST_F(CApi, proj_obj_alter_name) { ObjectKeeper keeper(obj); ASSERT_NE(obj, nullptr); - auto alteredObj = proj_obj_alter_name(m_ctxt, obj, "new name"); - ObjectKeeper keeper_alteredObj(alteredObj); - ASSERT_NE(alteredObj, nullptr); + { + auto alteredObj = proj_obj_alter_name(m_ctxt, obj, "new name"); + ObjectKeeper keeper_alteredObj(alteredObj); + ASSERT_NE(alteredObj, nullptr); + + EXPECT_EQ(std::string(proj_obj_get_name(alteredObj)), "new name"); + EXPECT_FALSE(proj_obj_is_deprecated(alteredObj)); + } - EXPECT_EQ(std::string(proj_obj_get_name(alteredObj)), "new name"); + { + auto alteredObj = + proj_obj_alter_name(m_ctxt, obj, "new name (deprecated)"); + ObjectKeeper keeper_alteredObj(alteredObj); + ASSERT_NE(alteredObj, nullptr); + + EXPECT_EQ(std::string(proj_obj_get_name(alteredObj)), "new name"); + EXPECT_TRUE(proj_obj_is_deprecated(alteredObj)); + } } // --------------------------------------------------------------------------- diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 243add6f..1f2ec323 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -513,6 +513,29 @@ TEST(wkt_parse, wkt1_geographic_old_datum_name_witout_EPSG_code) { // --------------------------------------------------------------------------- +TEST(wkt_parse, wkt1_geographic_deprecated) { + auto wkt = "GEOGCS[\"SAD69 (deprecated)\",\n" + " DATUM[\"South_American_Datum_1969\",\n" + " SPHEROID[\"GRS 1967\",6378160,298.247167427,\n" + " AUTHORITY[\"EPSG\",\"7036\"]],\n" + " AUTHORITY[\"EPSG\",\"6291\"]],\n" + " PRIMEM[\"Greenwich\",0,\n" + " AUTHORITY[\"EPSG\",\"8901\"]],\n" + " UNIT[\"degree\",0.0174532925199433,\n" + " AUTHORITY[\"EPSG\",\"9108\"]],\n" + " AUTHORITY[\"EPSG\",\"4291\"]]"; + auto obj = WKTParser() + .attachDatabaseContext(DatabaseContext::create()) + .createFromWKT(wkt); + auto crs = nn_dynamic_pointer_cast<GeographicCRS>(obj); + ASSERT_TRUE(crs != nullptr); + + EXPECT_EQ(crs->nameStr(), "SAD69"); + EXPECT_TRUE(crs->isDeprecated()); +} + +// --------------------------------------------------------------------------- + static std::string contentWKT2_EPSG_4326( "[\"WGS 84\",\n" " DATUM[\"World Geodetic System 1984\",\n" |
