diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-03-19 11:27:49 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2021-03-19 11:30:54 +0100 |
| commit | 219758a4c9cfa84d15c593b1d0239250606cb7a2 (patch) | |
| tree | 12fb702d3727e7b95bc98ab6f0ca4feba6262bbf /src/iso19111/factory.cpp | |
| parent | 76906029f3798ecaeb0a3f61d140d7714cc8524d (diff) | |
| download | PROJ-219758a4c9cfa84d15c593b1d0239250606cb7a2.tar.gz PROJ-219758a4c9cfa84d15c593b1d0239250606cb7a2.zip | |
SQL output: make it possible to export non-EPSG projection methods or methods and params lacking an explicit EPSG id
Diffstat (limited to 'src/iso19111/factory.cpp')
| -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; |
