From 57b00a63c6caee1a53961d542904f7c9b1f014c9 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 4 Dec 2018 16:22:44 +0100 Subject: Improve management of 'deprecated' suffix in object names --- src/crs.cpp | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'src/crs.cpp') 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(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(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(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(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(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()); -- cgit v1.2.3