aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-03-29 13:30:57 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-03-29 13:30:57 +0100
commit88f2661c9fd9fbf9d714a184243340cafb64d91d (patch)
treea7124077ba0dcba5ef7e4f6e51929f292fc4a5cd /src
parenta0dfcf28d3af1179847c75a2a8981cb7fe967ab8 (diff)
downloadPROJ-88f2661c9fd9fbf9d714a184243340cafb64d91d.tar.gz
PROJ-88f2661c9fd9fbf9d714a184243340cafb64d91d.zip
createOperations(): improve behaviour with input CRS from WKT that lacks intermediate IDs (fixes #1343)
Diffstat (limited to 'src')
-rw-r--r--src/iso19111/coordinateoperation.cpp147
1 files changed, 127 insertions, 20 deletions
diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp
index 24e5f8ab..15532a89 100644
--- a/src/iso19111/coordinateoperation.cpp
+++ b/src/iso19111/coordinateoperation.cpp
@@ -11311,16 +11311,37 @@ static bool hasIdentifiers(const CoordinateOperationNNPtr &op) {
static std::vector<crs::CRSNNPtr>
findCandidateGeodCRSForDatum(const io::AuthorityFactoryPtr &authFactory,
- const datum::GeodeticReferenceFramePtr &datum) {
+ const datum::GeodeticReferenceFrame *datum) {
std::vector<crs::CRSNNPtr> candidates;
- for (const auto &id : datum->identifiers()) {
- const auto &authName = *(id->codeSpace());
- const auto &code = id->code();
- if (!authName.empty()) {
- auto l_candidates = authFactory->createGeodeticCRSFromDatum(
- authName, code, std::string());
- for (const auto &candidate : l_candidates) {
- candidates.emplace_back(candidate);
+ assert(datum);
+ const auto &ids = datum->identifiers();
+ const auto &datumName = datum->nameStr();
+ if (!ids.empty()) {
+ for (const auto &id : ids) {
+ const auto &authName = *(id->codeSpace());
+ const auto &code = id->code();
+ if (!authName.empty()) {
+ auto l_candidates = authFactory->createGeodeticCRSFromDatum(
+ authName, code, std::string());
+ for (const auto &candidate : l_candidates) {
+ candidates.emplace_back(candidate);
+ }
+ }
+ }
+ } else if (datumName != "unknown" && datumName != "unnamed") {
+ auto matches = authFactory->createObjectsFromName(
+ datumName,
+ {io::AuthorityFactory::ObjectType::GEODETIC_REFERENCE_FRAME}, false,
+ 2);
+ if (matches.size() == 1) {
+ const auto &match = matches.front();
+ if (datum->_isEquivalentTo(
+ match.get(), util::IComparable::Criterion::EQUIVALENT) &&
+ !match->identifiers().empty()) {
+ return findCandidateGeodCRSForDatum(
+ authFactory,
+ dynamic_cast<const datum::GeodeticReferenceFrame *>(
+ match.get()));
}
}
}
@@ -11362,9 +11383,9 @@ void CoordinateOperationFactory::Private::createOperationsWithDatumPivot(
const auto &authFactory = context.context->getAuthorityFactory();
const auto candidatesSrcGeod(
- findCandidateGeodCRSForDatum(authFactory, geodSrc->datum()));
+ findCandidateGeodCRSForDatum(authFactory, geodSrc->datum().get()));
const auto candidatesDstGeod(
- findCandidateGeodCRSForDatum(authFactory, geodDst->datum()));
+ findCandidateGeodCRSForDatum(authFactory, geodDst->datum().get()));
auto createTransformations = [&](const crs::CRSNNPtr &candidateSrcGeod,
const crs::CRSNNPtr &candidateDstGeod,
@@ -11605,12 +11626,8 @@ CoordinateOperationFactory::Private::createOperations(
// but transformations are only available between their
// corresponding geocentric CRS.
const auto &srcDatum = geodSrc->datum();
- const bool srcHasDatumWithId =
- srcDatum && !srcDatum->identifiers().empty();
const auto &dstDatum = geodDst->datum();
- const bool dstHasDatumWithId =
- dstDatum && !dstDatum->identifiers().empty();
- if (srcHasDatumWithId && dstHasDatumWithId &&
+ if (srcDatum != nullptr && dstDatum != nullptr &&
!srcDatum->_isEquivalentTo(
dstDatum.get(), util::IComparable::Criterion::EQUIVALENT)) {
createOperationsWithDatumPivot(res, sourceCRS, targetCRS,
@@ -11955,6 +11972,31 @@ CoordinateOperationFactory::Private::createOperations(
// A bit odd case as we are comparing apples to oranges, but in case
// the vertical unit differ, do something useful.
if (vertSrc && geogDst) {
+
+ if (vertSrc->identifiers().empty()) {
+ const auto &authFactory = context.context->getAuthorityFactory();
+ const auto &vertSrcName = vertSrc->nameStr();
+ if (authFactory != nullptr && vertSrcName != "unnamed" &&
+ vertSrcName != "unknown") {
+ auto matches = authFactory->createObjectsFromName(
+ vertSrcName,
+ {io::AuthorityFactory::ObjectType::VERTICAL_CRS}, false, 2);
+ if (matches.size() == 1) {
+ const auto &match = matches.front();
+ if (vertSrc->_isEquivalentTo(
+ match.get(),
+ util::IComparable::Criterion::EQUIVALENT) &&
+ !match->identifiers().empty()) {
+ return createOperations(
+ NN_NO_CHECK(
+ util::nn_dynamic_pointer_cast<crs::VerticalCRS>(
+ match)),
+ targetCRS, context);
+ }
+ }
+ }
+ }
+
const double convSrc =
vertSrc->coordinateSystem()->axisList()[0]->unit().conversionToSI();
double convDst = 1.0;
@@ -12300,6 +12342,67 @@ CoordinateOperationFactory::Private::createOperations(
// ---------------------------------------------------------------------------
+static crs::CRSNNPtr
+getResolvedCRS(const crs::CRSNNPtr &crs,
+ const CoordinateOperationContextNNPtr &context) {
+ const auto &authFactory = context->getAuthorityFactory();
+
+ auto projectedCrs = dynamic_cast<crs::ProjectedCRS *>(crs.get());
+ if (projectedCrs && authFactory) {
+ const auto &ids = projectedCrs->identifiers();
+ if (!ids.empty() && projectedCrs->baseCRS()->identifiers().empty()) {
+ const auto tmpAuthFactory = io::AuthorityFactory::create(
+ authFactory->databaseContext(), *ids.front()->codeSpace());
+ try {
+ crs::CRSNNPtr resolvedCrs(
+ tmpAuthFactory->createProjectedCRS(ids.front()->code()));
+ if (resolvedCrs->_isEquivalentTo(
+ crs.get(), util::IComparable::Criterion::EQUIVALENT)) {
+ return resolvedCrs;
+ }
+ } catch (const std::exception &) {
+ }
+ }
+ }
+
+ auto compoundCrs = dynamic_cast<crs::CompoundCRS *>(crs.get());
+ // If we get a CompoundCRS that has an EPSG code, but whose component CRS
+ // lack one, typically from WKT2, this might be an issue to get proper
+ // results in createOperations(), so import the CompoundCRS from the
+ // registry, and if equivalent to the original one, then use the version
+ // from the registry.
+ if (compoundCrs && authFactory) {
+ const auto &ids = compoundCrs->identifiers();
+ if (!ids.empty()) {
+ const auto &components = compoundCrs->componentReferenceSystems();
+ bool hasMissingId = false;
+ for (const auto &comp : components) {
+ if (comp->identifiers().empty()) {
+ hasMissingId = true;
+ break;
+ }
+ }
+ if (hasMissingId) {
+ const auto tmpAuthFactory = io::AuthorityFactory::create(
+ authFactory->databaseContext(), *ids.front()->codeSpace());
+ try {
+ crs::CRSNNPtr resolvedCrs(
+ tmpAuthFactory->createCompoundCRS(ids.front()->code()));
+ if (resolvedCrs->_isEquivalentTo(
+ crs.get(),
+ util::IComparable::Criterion::EQUIVALENT)) {
+ return resolvedCrs;
+ }
+ } catch (const std::exception &) {
+ }
+ }
+ }
+ }
+ return crs;
+}
+
+// ---------------------------------------------------------------------------
+
/** \brief Find a list of CoordinateOperation from sourceCRS to targetCRS.
*
* The operations are sorted with the most relevant ones first: by
@@ -12328,10 +12431,14 @@ CoordinateOperationFactory::createOperations(
auto l_sourceCRS = srcBoundCRS ? NN_NO_CHECK(srcBoundCRS) : sourceCRS;
auto l_targetCRS = targetBoundCRS ? NN_NO_CHECK(targetBoundCRS) : targetCRS;
- Private::Context contextPrivate(sourceCRS, targetCRS, context);
- return filterAndSort(
- Private::createOperations(l_sourceCRS, l_targetCRS, contextPrivate),
- context, l_sourceCRS, l_targetCRS);
+ auto l_resolvedSourceCRS = getResolvedCRS(l_sourceCRS, context);
+ auto l_resolvedTargetCRS = getResolvedCRS(l_targetCRS, context);
+ Private::Context contextPrivate(l_resolvedSourceCRS, l_resolvedTargetCRS,
+ context);
+ return filterAndSort(Private::createOperations(l_resolvedSourceCRS,
+ l_resolvedTargetCRS,
+ contextPrivate),
+ context, l_resolvedSourceCRS, l_resolvedTargetCRS);
}
// ---------------------------------------------------------------------------