diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-09-05 16:06:55 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2021-09-05 16:06:55 +0200 |
| commit | 01559894ca1e6aa1ae983d4069db55a8c7ec4aec (patch) | |
| tree | 06dab63309325a4c094eb8153c87a2b8458446f4 /src/iso19111 | |
| parent | 71b372e6f08b2f40fbd043c80b56bdb8d2c0b5a0 (diff) | |
| download | PROJ-01559894ca1e6aa1ae983d4069db55a8c7ec4aec.tar.gz PROJ-01559894ca1e6aa1ae983d4069db55a8c7ec4aec.zip | |
getInsertStatementsFor(): re-order projection parameters according to their canonical order if needed
Diffstat (limited to 'src/iso19111')
| -rw-r--r-- | src/iso19111/factory.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 508c3513..8b54160d 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -2363,6 +2363,7 @@ std::vector<std::string> DatabaseContext::Private::getInsertStatementsFor( const auto &methodIds = method->identifiers(); std::string methodAuthName; std::string methodCode; + const operation::MethodMapping *methodMapping = nullptr; if (methodIds.empty()) { const int epsgCode = method->getEPSGCode(); if (epsgCode > 0) { @@ -2374,7 +2375,6 @@ std::vector<std::string> DatabaseContext::Private::getInsertStatementsFor( 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( @@ -2399,18 +2399,52 @@ std::vector<std::string> DatabaseContext::Private::getInsertStatementsFor( methodAuthName = *(methodId->codeSpace()); methodCode = methodId->code(); } + auto sql = formatStatement("INSERT INTO conversion VALUES(" "'%q','%q','%q','','%q','%q','%q'", convAuthName.c_str(), convCode.c_str(), conversion->nameStr().c_str(), methodAuthName.c_str(), methodCode.c_str(), method->nameStr().c_str()); - const auto &values = conversion->parameterValues(); - if (values.size() > N_MAX_PARAMS) { + const auto &srcValues = conversion->parameterValues(); + if (srcValues.size() > N_MAX_PARAMS) { throw FactoryException("Cannot insert projection with more than " + toString(static_cast<int>(N_MAX_PARAMS)) + " parameters"); } + + std::vector<operation::GeneralParameterValueNNPtr> values; + if (methodMapping == nullptr) { + if (methodAuthName == metadata::Identifier::EPSG) { + methodMapping = operation::getMapping(atoi(methodCode.c_str())); + } else { + methodMapping = + operation::getMapping(method->nameStr().c_str()); + } + } + if (methodMapping != nullptr) { + // Re-order projection parameters in their reference order + for (size_t j = 0; methodMapping->params[j] != nullptr; ++j) { + for (size_t i = 0; i < srcValues.size(); ++i) { + auto opParamValue = dynamic_cast< + const operation::OperationParameterValue *>( + srcValues[i].get()); + if (!opParamValue) { + throw FactoryException("Cannot insert projection with " + "non-OperationParameterValue"); + } + if (methodMapping->params[j]->wkt2_name && + opParamValue->parameter()->nameStr() == + methodMapping->params[j]->wkt2_name) { + values.emplace_back(srcValues[i]); + } + } + } + } + if (values.size() != srcValues.size()) { + values = srcValues; + } + for (const auto &genOpParamvalue : values) { auto opParamValue = dynamic_cast<const operation::OperationParameterValue *>( |
