diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-03-19 13:07:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-19 13:07:04 +0100 |
| commit | 338a3c4a267bfdca3256525c423e04fcda7d27b9 (patch) | |
| tree | cd632686544c866a738420a20d12cb715a5f9d8a /src | |
| parent | 663a77095defb6a3a96faf75995a77e1964c9843 (diff) | |
| parent | ed9b63dcce0037d8ebb3a34e764c16ef594f3559 (diff) | |
| download | PROJ-338a3c4a267bfdca3256525c423e04fcda7d27b9.tar.gz PROJ-338a3c4a267bfdca3256525c423e04fcda7d27b9.zip | |
Merge pull request #2585 from rouault/insert_sql_improvements
SQL output: make it possible to export non-EPSG projection methods or…
Diffstat (limited to 'src')
| -rw-r--r-- | src/iso19111/factory.cpp | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 1ec741e1..86c7b840 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -2171,13 +2171,44 @@ std::vector<std::string> DatabaseContext::Private::getInsertStatementsFor( { const auto &method = conversion->method(); const auto &methodIds = method->identifiers(); + std::string methodAuthName; + std::string methodCode; if (methodIds.empty()) { - throw FactoryException( - "Cannot insert projection with method without identifier"); + const int epsgCode = method->getEPSGCode(); + if (epsgCode > 0) { + methodAuthName = metadata::Identifier::EPSG; + methodCode = toString(epsgCode); + } else { + const auto &methodName = method->nameStr(); + size_t nProjectionMethodMappings = 0; + const auto projectionMethodMappings = + operation::getProjectionMethodMappings( + nProjectionMethodMappings); + const operation::MethodMapping *methodMapping = nullptr; + for (size_t i = 0; i < nProjectionMethodMappings; ++i) { + const auto &mapping = projectionMethodMappings[i]; + if (metadata::Identifier::isEquivalentName( + mapping.wkt2_name, methodName.c_str())) { + methodMapping = &mapping; + } + } + if (methodMapping == nullptr || + methodMapping->proj_name_main == nullptr) { + throw FactoryException("Cannot insert projection with " + "method without identifier"); + } + methodAuthName = "PROJ"; + methodCode = methodMapping->proj_name_main; + if (methodMapping->proj_name_aux) { + methodCode += ' '; + methodCode += methodMapping->proj_name_aux; + } + } + } else { + const auto &methodId = methodIds.front(); + methodAuthName = *(methodId->codeSpace()); + methodCode = methodId->code(); } - const auto &methodId = methodIds.front(); - const auto &methodAuthName = *(methodId->codeSpace()); - const auto &methodCode = methodId->code(); auto sql = formatStatement("INSERT INTO conversion VALUES(" "'%q','%q','%q','','%q','%q','%q'", convAuthName.c_str(), convCode.c_str(), @@ -2200,14 +2231,22 @@ std::vector<std::string> DatabaseContext::Private::getInsertStatementsFor( } const auto ¶m = opParamValue->parameter(); const auto ¶mIds = param->identifiers(); + std::string paramAuthName; + std::string paramCode; if (paramIds.empty()) { - throw FactoryException( - "Cannot insert projection with method parameter " - "without identifier"); + const int paramEPSGCode = param->getEPSGCode(); + if (paramEPSGCode == 0) { + throw FactoryException( + "Cannot insert projection with method parameter " + "without identifier"); + } + paramAuthName = metadata::Identifier::EPSG; + paramCode = toString(paramEPSGCode); + } else { + const auto ¶mId = paramIds.front(); + paramAuthName = *(paramId->codeSpace()); + paramCode = paramId->code(); } - const auto ¶mId = paramIds.front(); - const auto ¶mAuthName = *(paramId->codeSpace()); - const auto ¶mCode = paramId->code(); const auto &value = opParamValue->parameterValue()->value(); const auto &unit = value.unit(); std::string uomAuthName; |
