diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-09-05 15:41:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-05 15:41:40 +0200 |
| commit | 71b372e6f08b2f40fbd043c80b56bdb8d2c0b5a0 (patch) | |
| tree | eaae225629ae6101db6094b046f319df4f6aba7a /src/iso19111 | |
| parent | 09367628bfe698d6a73a1b928bcf611ea675103d (diff) | |
| parent | b91af0075a7e8a189e2cd443a823a0798e0b9ed9 (diff) | |
| download | PROJ-71b372e6f08b2f40fbd043c80b56bdb8d2c0b5a0.tar.gz PROJ-71b372e6f08b2f40fbd043c80b56bdb8d2c0b5a0.zip | |
Merge pull request #2841 from rouault/cppcheck_fixes
Cppcheck fixes
Diffstat (limited to 'src/iso19111')
| -rw-r--r-- | src/iso19111/crs.cpp | 14 | ||||
| -rw-r--r-- | src/iso19111/io.cpp | 127 | ||||
| -rw-r--r-- | src/iso19111/operation/conversion.cpp | 9 |
3 files changed, 70 insertions, 80 deletions
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index a15758ab..7c8fcd81 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -2274,6 +2274,7 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { auto searchByDatumCode = [this, &authorityFactory, &res, &geodetic_crs_type, crsCriterion, &dbContext](const common::IdentifiedObjectNNPtr &l_datum) { + bool resModified = false; for (const auto &id : l_datum->identifiers()) { try { auto tempRes = @@ -2284,11 +2285,13 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { if (_isEquivalentTo(crs.get(), crsCriterion, dbContext)) { res.emplace_back(crs, 70); + resModified = true; } } } catch (const std::exception &) { } } + return resModified; }; auto searchByEllipsoid = [this, &authorityFactory, &res, &thisDatum, @@ -2331,8 +2334,8 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { } }; - const auto searchByDatumOrEllipsoid = [&authorityFactory, &res, - &thisDatum, searchByDatumCode, + const auto searchByDatumOrEllipsoid = [&authorityFactory, &thisDatum, + searchByDatumCode, searchByEllipsoid]() { if (!thisDatum->identifiers().empty()) { searchByDatumCode(thisDatum); @@ -2342,11 +2345,12 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { {io::AuthorityFactory::ObjectType:: GEODETIC_REFERENCE_FRAME}, false); - const size_t sizeBefore = res.size(); + bool resModified = false; for (const auto &candidateDatum : candidateDatums) { - searchByDatumCode(candidateDatum); + if (searchByDatumCode(candidateDatum)) + resModified = true; } - if (sizeBefore == res.size()) { + if (!resModified) { searchByEllipsoid(); } } diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 161441ee..a1b06ae7 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -6773,65 +6773,61 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text, const auto searchObject = [&factory]( const std::string &objectName, bool approximateMatch, - const std::vector<AuthorityFactory::ObjectType> &objectTypes, - bool &goOn) { - constexpr size_t limitResultCount = 10; - auto res = factory->createObjectsFromName( - objectName, objectTypes, approximateMatch, - limitResultCount); - if (res.size() == 1) { - return res.front(); - } - if (res.size() > 1) { - if (objectTypes.size() == 1 && - objectTypes[0] == AuthorityFactory::ObjectType::CRS) { - for (size_t ndim = 2; ndim <= 3; ndim++) { - for (const auto &obj : res) { - auto crs = dynamic_cast<crs::GeographicCRS *>( - obj.get()); - if (crs && crs->coordinateSystem() - ->axisList() - .size() == ndim) { - return obj; - } + const std::vector<AuthorityFactory::ObjectType> &objectTypes) + -> IdentifiedObjectPtr { + constexpr size_t limitResultCount = 10; + auto res = factory->createObjectsFromName( + objectName, objectTypes, approximateMatch, limitResultCount); + if (res.size() == 1) { + return res.front().as_nullable(); + } + if (res.size() > 1) { + if (objectTypes.size() == 1 && + objectTypes[0] == AuthorityFactory::ObjectType::CRS) { + for (size_t ndim = 2; ndim <= 3; ndim++) { + for (const auto &obj : res) { + auto crs = + dynamic_cast<crs::GeographicCRS *>(obj.get()); + if (crs && + crs->coordinateSystem()->axisList().size() == + ndim) { + return obj.as_nullable(); } } } + } - std::string msg("several objects matching this name: "); - bool first = true; - for (const auto &obj : res) { - if (msg.size() > 200) { - msg += ", ..."; - break; - } - if (!first) { - msg += ", "; - } - first = false; - msg += obj->nameStr(); + std::string msg("several objects matching this name: "); + bool first = true; + for (const auto &obj : res) { + if (msg.size() > 200) { + msg += ", ..."; + break; } - throw ParsingException(msg); + if (!first) { + msg += ", "; + } + first = false; + msg += obj->nameStr(); } - goOn = true; - throw ParsingException("dummy"); - }; + throw ParsingException(msg); + } + return nullptr; + }; const auto searchCRS = [&searchObject](const std::string &objectName) { - bool goOn = false; const auto objectTypes = std::vector<AuthorityFactory::ObjectType>{ AuthorityFactory::ObjectType::CRS}; - try { + { constexpr bool approximateMatch = false; - return searchObject(objectName, approximateMatch, objectTypes, - goOn); - } catch (const std::exception &) { - if (!goOn) - throw; + auto ret = + searchObject(objectName, approximateMatch, objectTypes); + if (ret) + return ret; } + constexpr bool approximateMatch = true; - return searchObject(objectName, approximateMatch, objectTypes, - goOn); + return searchObject(objectName, approximateMatch, objectTypes); }; // strings like "WGS 84 + EGM96 height" @@ -6841,8 +6837,8 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text, if (tokensCompound.size() == 2) { auto obj1 = searchCRS(tokensCompound[0]); auto obj2 = searchCRS(tokensCompound[1]); - auto crs1 = util::nn_dynamic_pointer_cast<CRS>(obj1); - auto crs2 = util::nn_dynamic_pointer_cast<CRS>(obj2); + auto crs1 = std::dynamic_pointer_cast<CRS>(obj1); + auto crs2 = std::dynamic_pointer_cast<CRS>(obj2); if (crs1 && crs2) { compoundCRS = CompoundCRS::create( @@ -6862,28 +6858,19 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text, // Fourth pass: approximate match on other objects for (int pass = 0; pass <= 3; ++pass) { const bool approximateMatch = (pass >= 2); - bool goOn = false; - try { - return searchObject( - text, approximateMatch, - (pass == 0 || pass == 2) - ? std::vector< - AuthorityFactory::ObjectType>{AuthorityFactory:: - ObjectType::CRS} - : std::vector< - AuthorityFactory:: - ObjectType>{AuthorityFactory::ObjectType:: - ELLIPSOID, - AuthorityFactory::ObjectType:: - DATUM, - AuthorityFactory::ObjectType:: - DATUM_ENSEMBLE, - AuthorityFactory::ObjectType:: - COORDINATE_OPERATION}, - goOn); - } catch (const std::exception &) { - if (!goOn) - throw; + auto ret = searchObject( + text, approximateMatch, + (pass == 0 || pass == 2) + ? std::vector< + AuthorityFactory::ObjectType>{AuthorityFactory:: + ObjectType::CRS} + : std::vector<AuthorityFactory::ObjectType>{ + AuthorityFactory::ObjectType::ELLIPSOID, + AuthorityFactory::ObjectType::DATUM, + AuthorityFactory::ObjectType::DATUM_ENSEMBLE, + AuthorityFactory::ObjectType::COORDINATE_OPERATION}); + if (ret) { + return NN_NO_CHECK(ret); } if (compoundCRS) { return NN_NO_CHECK(compoundCRS); diff --git a/src/iso19111/operation/conversion.cpp b/src/iso19111/operation/conversion.cpp index 3cc452f8..3d09c9fa 100644 --- a/src/iso19111/operation/conversion.cpp +++ b/src/iso19111/operation/conversion.cpp @@ -2359,12 +2359,11 @@ ConversionNNPtr Conversion::createAxisOrderReversal(bool is3D) { createMethodMapNameEPSGCode( EPSG_CODE_METHOD_AXIS_ORDER_REVERSAL_3D), {}, {}); - } else { - return create(createMapNameEPSGCode(AXIS_ORDER_CHANGE_2D_NAME, 15498), - createMethodMapNameEPSGCode( - EPSG_CODE_METHOD_AXIS_ORDER_REVERSAL_2D), - {}, {}); } + return create( + createMapNameEPSGCode(AXIS_ORDER_CHANGE_2D_NAME, 15498), + createMethodMapNameEPSGCode(EPSG_CODE_METHOD_AXIS_ORDER_REVERSAL_2D), + {}, {}); } // --------------------------------------------------------------------------- |
