diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-03-27 12:58:42 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-03-27 12:58:42 +0100 |
| commit | e3806d999a86a1ab0e832f1ab6586ad181f64be1 (patch) | |
| tree | 8e8c53f76711d77f5e20ab20ebfccdd9390857f3 /src/apps/projinfo.cpp | |
| parent | 3987c3f22206768e875b45ff10b3824c52903d09 (diff) | |
| download | PROJ-e3806d999a86a1ab0e832f1ab6586ad181f64be1.tar.gz PROJ-e3806d999a86a1ab0e832f1ab6586ad181f64be1.zip | |
projinfo: caught uncaught exception. Coverity CID 193527
Diffstat (limited to 'src/apps/projinfo.cpp')
| -rw-r--r-- | src/apps/projinfo.cpp | 119 |
1 files changed, 64 insertions, 55 deletions
diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 7d4a8399..9d724522 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -1005,69 +1005,78 @@ int main(int argc, char **argv) { } if (!user_string.empty()) { - auto obj(buildObject(dbContext, user_string, objectKind, "input string", - buildBoundCRSToWGS84, allowUseIntermediateCRS, - outputOpt.quiet)); - if (guessDialect) { - auto dialect = WKTParser().guessDialect(user_string); - std::cout << "Guessed WKT dialect: "; - if (dialect == WKTParser::WKTGuessedDialect::WKT2_2018) { - std::cout << "WKT2_2018"; - } else if (dialect == WKTParser::WKTGuessedDialect::WKT2_2015) { - std::cout << "WKT2_2015"; - } else if (dialect == WKTParser::WKTGuessedDialect::WKT1_GDAL) { - std::cout << "WKT1_GDAL"; - } else if (dialect == WKTParser::WKTGuessedDialect::WKT1_ESRI) { - std::cout << "WKT1_ESRI"; - } else { - std::cout << "Not WKT / unknown"; + try { + auto obj(buildObject(dbContext, user_string, objectKind, + "input string", buildBoundCRSToWGS84, + allowUseIntermediateCRS, outputOpt.quiet)); + if (guessDialect) { + auto dialect = WKTParser().guessDialect(user_string); + std::cout << "Guessed WKT dialect: "; + if (dialect == WKTParser::WKTGuessedDialect::WKT2_2018) { + std::cout << "WKT2_2018"; + } else if (dialect == WKTParser::WKTGuessedDialect::WKT2_2015) { + std::cout << "WKT2_2015"; + } else if (dialect == WKTParser::WKTGuessedDialect::WKT1_GDAL) { + std::cout << "WKT1_GDAL"; + } else if (dialect == WKTParser::WKTGuessedDialect::WKT1_ESRI) { + std::cout << "WKT1_ESRI"; + } else { + std::cout << "Not WKT / unknown"; + } + std::cout << std::endl; } - std::cout << std::endl; - } - outputObject(dbContext, obj, allowUseIntermediateCRS, outputOpt); - if (identify) { - auto crs = dynamic_cast<CRS *>(obj.get()); - if (crs) { - try { - auto res = crs->identify( - dbContext - ? AuthorityFactory::create(NN_NO_CHECK(dbContext), - authority) - .as_nullable() - : nullptr); - std::cout << std::endl; - std::cout << "Identification match count: " << res.size() - << std::endl; - for (const auto &pair : res) { - const auto &identifiedCRS = pair.first; - const auto &ids = identifiedCRS->identifiers(); - if (!ids.empty()) { - std::cout << *ids[0]->codeSpace() << ":" - << ids[0]->code() << ": " << pair.second - << " %" << std::endl; - } else { - auto boundCRS = - dynamic_cast<BoundCRS *>(identifiedCRS.get()); - if (boundCRS && - !boundCRS->baseCRS()->identifiers().empty()) { - const auto &idsBase = - boundCRS->baseCRS()->identifiers(); - std::cout << "BoundCRS of " - << *idsBase[0]->codeSpace() << ":" - << idsBase[0]->code() << ": " + outputObject(dbContext, obj, allowUseIntermediateCRS, outputOpt); + if (identify) { + auto crs = dynamic_cast<CRS *>(obj.get()); + if (crs) { + try { + auto res = crs->identify( + dbContext + ? AuthorityFactory::create( + NN_NO_CHECK(dbContext), authority) + .as_nullable() + : nullptr); + std::cout << std::endl; + std::cout + << "Identification match count: " << res.size() + << std::endl; + for (const auto &pair : res) { + const auto &identifiedCRS = pair.first; + const auto &ids = identifiedCRS->identifiers(); + if (!ids.empty()) { + std::cout << *ids[0]->codeSpace() << ":" + << ids[0]->code() << ": " << pair.second << " %" << std::endl; } else { - std::cout - << "un-identifier CRS: " << pair.second - << " %" << std::endl; + auto boundCRS = dynamic_cast<BoundCRS *>( + identifiedCRS.get()); + if (boundCRS && + !boundCRS->baseCRS() + ->identifiers() + .empty()) { + const auto &idsBase = + boundCRS->baseCRS()->identifiers(); + std::cout << "BoundCRS of " + << *idsBase[0]->codeSpace() << ":" + << idsBase[0]->code() << ": " + << pair.second << " %" + << std::endl; + } else { + std::cout + << "un-identifier CRS: " << pair.second + << " %" << std::endl; + } } } + } catch (const std::exception &e) { + std::cerr << "Identification failed: " << e.what() + << std::endl; } - } catch (const std::exception &e) { - std::cerr << "Identification failed: " << e.what() - << std::endl; } } + } catch (const std::exception &e) { + std::cerr << "buildObject failed: " << e.what() << std::endl; + std::exit(1); } } else { |
