aboutsummaryrefslogtreecommitdiff
path: root/src/iso19111/factory.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-04-18 14:11:44 +0200
committerEven Rouault <even.rouault@spatialys.com>2021-04-18 14:28:34 +0200
commitdd79ca70edcee3dc4f5485a87e11e52cfa2ea041 (patch)
tree70cff5cb99b0608ec9aaa1d237abb5bb4e6b40a0 /src/iso19111/factory.cpp
parenta850aac5e0de3f86f2e4cf29f211e88744db5133 (diff)
downloadPROJ-dd79ca70edcee3dc4f5485a87e11e52cfa2ea041.tar.gz
PROJ-dd79ca70edcee3dc4f5485a87e11e52cfa2ea041.zip
createOperations(): fix Geog to Geog when one is deprecated (fix master regression)
Diffstat (limited to 'src/iso19111/factory.cpp')
-rw-r--r--src/iso19111/factory.cpp73
1 files changed, 43 insertions, 30 deletions
diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp
index 19db111b..3ced25d3 100644
--- a/src/iso19111/factory.cpp
+++ b/src/iso19111/factory.cpp
@@ -6752,42 +6752,55 @@ AuthorityFactory::createBetweenGeodeticCRSWithDatumBasedIntermediates(
return listTmp;
}
- // Find all geodetic CRS that share the same datum as the source CRS
- SQLResultSet listSourceCRS;
- {
- const auto res = d->run("SELECT datum_auth_name, datum_code FROM "
- "geodetic_crs WHERE auth_name = ? AND code = ?",
- {sourceCRSAuthName, sourceCRSCode});
- if (res.size() != 1) {
- return listTmp;
+ const auto GetListCRSWithSameDatum = [this](const crs::GeodeticCRS *crs,
+ const std::string &crsAuthName,
+ const std::string &crsCode) {
+ // Find all geodetic CRS that share the same datum as the CRS
+ SQLResultSet listCRS;
+
+ const common::IdentifiedObject *obj = crs->datum().get();
+ if (obj == nullptr)
+ obj = crs->datumEnsemble().get();
+ assert(obj != nullptr);
+ const auto &ids = obj->identifiers();
+ std::string datumAuthName;
+ std::string datumCode;
+ if (!ids.empty()) {
+ const auto &id = ids.front();
+ datumAuthName = *(id->codeSpace());
+ datumCode = id->code();
+ } else {
+ const auto res =
+ d->run("SELECT datum_auth_name, datum_code FROM "
+ "geodetic_crs WHERE auth_name = ? AND code = ?",
+ {crsAuthName, crsCode});
+ if (res.size() != 1) {
+ return listCRS;
+ }
+ const auto &row = res.front();
+ datumAuthName = row[0];
+ datumCode = row[1];
}
- const auto &row = res.front();
- const auto sourceDatumAuthName = row[0];
- const auto sourceDatumCode = row[1];
- listSourceCRS =
+ listCRS =
d->run("SELECT auth_name, code FROM geodetic_crs WHERE "
"datum_auth_name = ? AND datum_code = ? AND deprecated = 0",
- {sourceDatumAuthName, sourceDatumCode});
- }
-
- // Find all geodetic CRS that share the same datum as the target CRS
- SQLResultSet listTargetCRS;
- {
- const auto res = d->run("SELECT datum_auth_name, datum_code FROM "
- "geodetic_crs WHERE auth_name = ? AND code = ?",
- {targetCRSAuthName, targetCRSCode});
- if (res.size() != 1) {
- return listTmp;
+ {datumAuthName, datumCode});
+ if (listCRS.empty()) {
+ // Can happen if the CRS is deprecated
+ listCRS.emplace_back(SQLRow{crsAuthName, crsCode});
}
- const auto &row = res.front();
- const auto targetDatumAuthName = row[0];
- const auto targetDatumCode = row[1];
+ return listCRS;
+ };
- listTargetCRS =
- d->run("SELECT auth_name, code FROM geodetic_crs WHERE "
- "datum_auth_name = ? AND datum_code = ? AND deprecated = 0",
- {targetDatumAuthName, targetDatumCode});
+ const SQLResultSet listSourceCRS = GetListCRSWithSameDatum(
+ sourceGeodCRS, sourceCRSAuthName, sourceCRSCode);
+ const SQLResultSet listTargetCRS = GetListCRSWithSameDatum(
+ targetGeodCRS, targetCRSAuthName, targetCRSCode);
+ if (listSourceCRS.empty() || listTargetCRS.empty()) {
+ // would happen only if we had CRS objects in the database without a
+ // link to a datum.
+ return listTmp;
}
ListOfParams params;