aboutsummaryrefslogtreecommitdiff
path: root/src/iso19111/operation/coordinateoperationfactory.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-03-03 17:45:53 +0100
committerEven Rouault <even.rouault@spatialys.com>2021-03-03 17:45:53 +0100
commit095731d53405309c38bebe31af51d141f6319f1a (patch)
treeefa9f1e916c1c1373298900ac4e66702beec8f35 /src/iso19111/operation/coordinateoperationfactory.cpp
parent9e2eb067585b9a61b2b5e636547ac80dd4d01d06 (diff)
downloadPROJ-095731d53405309c38bebe31af51d141f6319f1a.tar.gz
PROJ-095731d53405309c38bebe31af51d141f6319f1a.zip
Reformat code with clang-format-10 from ubuntu 20.04
Diffstat (limited to 'src/iso19111/operation/coordinateoperationfactory.cpp')
-rw-r--r--src/iso19111/operation/coordinateoperationfactory.cpp261
1 files changed, 132 insertions, 129 deletions
diff --git a/src/iso19111/operation/coordinateoperationfactory.cpp b/src/iso19111/operation/coordinateoperationfactory.cpp
index e4b989c8..44d9b570 100644
--- a/src/iso19111/operation/coordinateoperationfactory.cpp
+++ b/src/iso19111/operation/coordinateoperationfactory.cpp
@@ -30,8 +30,8 @@
#define FROM_PROJ_CPP
#endif
-#include "proj/coordinateoperation.hpp"
#include "proj/common.hpp"
+#include "proj/coordinateoperation.hpp"
#include "proj/crs.hpp"
#include "proj/io.hpp"
#include "proj/metadata.hpp"
@@ -1892,8 +1892,8 @@ struct MyPROJStringExportableGeodToGeod final
~MyPROJStringExportableGeodToGeod() override;
void
- // cppcheck-suppress functionStatic
- _exportToPROJString(io::PROJStringFormatter *formatter) const override {
+ // cppcheck-suppress functionStatic
+ _exportToPROJString(io::PROJStringFormatter *formatter) const override {
formatter->startInversion();
geodSrc->_exportToPROJString(formatter);
@@ -1922,8 +1922,8 @@ struct MyPROJStringExportableHorizVertical final
~MyPROJStringExportableHorizVertical() override;
void
- // cppcheck-suppress functionStatic
- _exportToPROJString(io::PROJStringFormatter *formatter) const override {
+ // cppcheck-suppress functionStatic
+ _exportToPROJString(io::PROJStringFormatter *formatter) const override {
formatter->pushOmitZUnitConversion();
@@ -1970,8 +1970,8 @@ struct MyPROJStringExportableHorizVerticalHorizPROJBased final
~MyPROJStringExportableHorizVerticalHorizPROJBased() override;
void
- // cppcheck-suppress functionStatic
- _exportToPROJString(io::PROJStringFormatter *formatter) const override {
+ // cppcheck-suppress functionStatic
+ _exportToPROJString(io::PROJStringFormatter *formatter) const override {
formatter->pushOmitZUnitConversion();
@@ -2321,10 +2321,9 @@ CoordinateOperationFactory::Private::createOperationsGeogToGeog(
}
// Do they differ by vertical units ?
- if (vconvSrc != vconvDst &&
- geogSrc->ellipsoid()->_isEquivalentTo(
- geogDst->ellipsoid().get(),
- util::IComparable::Criterion::EQUIVALENT)) {
+ if (vconvSrc != vconvDst && geogSrc->ellipsoid()->_isEquivalentTo(
+ geogDst->ellipsoid().get(),
+ util::IComparable::Criterion::EQUIVALENT)) {
if (offset_pm.value() == 0 && !axisReversal2D && !axisReversal3D) {
// If only by vertical units, use a Change of Vertical
// Unit
@@ -3267,7 +3266,6 @@ CoordinateOperationFactory::Private::createOperationsGeogToVertFromGeoid(
const auto useTransf = [&sourceCRS, &targetCRS, &context,
vertDst](const CoordinateOperationNNPtr &op) {
-
// If the source geographic CRS has a non-metre vertical unit, we need
// to create an intermediate and operation to do the vertical unit
// conversion from that vertical unit to the one of the geographic CRS
@@ -3324,85 +3322,86 @@ CoordinateOperationFactory::Private::createOperationsGeogToVertFromGeoid(
return ret;
};
- const auto getProjGeoidTransformation = [&sourceCRS, &targetCRS, &vertDst,
- &context](
- const CoordinateOperationNNPtr &model,
- const std::string &projFilename) {
-
- const auto getNameVertCRSMetre = [](const std::string &name) {
- if (name.empty())
- return std::string("unnamed");
- auto ret(name);
- bool haveOriginalUnit = false;
- if (name.back() == ')') {
- const auto pos = ret.rfind(" (");
+ const auto getProjGeoidTransformation =
+ [&sourceCRS, &targetCRS, &vertDst,
+ &context](const CoordinateOperationNNPtr &model,
+ const std::string &projFilename) {
+ const auto getNameVertCRSMetre = [](const std::string &name) {
+ if (name.empty())
+ return std::string("unnamed");
+ auto ret(name);
+ bool haveOriginalUnit = false;
+ if (name.back() == ')') {
+ const auto pos = ret.rfind(" (");
+ if (pos != std::string::npos) {
+ haveOriginalUnit = true;
+ ret = ret.substr(0, pos);
+ }
+ }
+ const auto pos = ret.rfind(" depth");
if (pos != std::string::npos) {
- haveOriginalUnit = true;
- ret = ret.substr(0, pos);
+ ret = ret.substr(0, pos) + " height";
}
- }
- const auto pos = ret.rfind(" depth");
- if (pos != std::string::npos) {
- ret = ret.substr(0, pos) + " height";
- }
- if (!haveOriginalUnit) {
- ret += " (metre)";
- }
- return ret;
- };
+ if (!haveOriginalUnit) {
+ ret += " (metre)";
+ }
+ return ret;
+ };
- const auto &axis = vertDst->coordinateSystem()->axisList()[0];
- const auto &authFactory = context.context->getAuthorityFactory();
- const auto dbContext =
- authFactory ? authFactory->databaseContext().as_nullable()
- : nullptr;
+ const auto &axis = vertDst->coordinateSystem()->axisList()[0];
+ const auto &authFactory = context.context->getAuthorityFactory();
+ const auto dbContext =
+ authFactory ? authFactory->databaseContext().as_nullable()
+ : nullptr;
- const auto geogSrcCRS =
- dynamic_cast<crs::GeographicCRS *>(model->interpolationCRS().get())
- ? NN_NO_CHECK(model->interpolationCRS())
- : sourceCRS->demoteTo2D(std::string(), dbContext)
- ->promoteTo3D(std::string(), dbContext);
- const auto vertCRSMetre =
- axis->unit() == common::UnitOfMeasure::METRE &&
- axis->direction() == cs::AxisDirection::UP
- ? targetCRS
- : util::nn_static_pointer_cast<crs::CRS>(
- crs::VerticalCRS::create(
- util::PropertyMap().set(
- common::IdentifiedObject::NAME_KEY,
- getNameVertCRSMetre(targetCRS->nameStr())),
- vertDst->datum(), vertDst->datumEnsemble(),
- cs::VerticalCS::createGravityRelatedHeight(
- common::UnitOfMeasure::METRE)));
- const auto properties = util::PropertyMap().set(
- common::IdentifiedObject::NAME_KEY,
- buildOpName("Transformation", vertCRSMetre, geogSrcCRS));
-
- // Try to find a representative value for the accuracy of this grid
- // from the registered transformations.
- std::vector<metadata::PositionalAccuracyNNPtr> accuracies;
- const auto &modelAccuracies = model->coordinateOperationAccuracies();
- if (modelAccuracies.empty()) {
- if (authFactory) {
- const auto transformationsForGrid =
- io::DatabaseContext::getTransformationsForGridName(
- authFactory->databaseContext(), projFilename);
- double accuracy = -1;
- for (const auto &transf : transformationsForGrid) {
- accuracy = std::max(accuracy, getAccuracy(transf));
- }
- if (accuracy >= 0) {
- accuracies.emplace_back(
- metadata::PositionalAccuracy::create(
- toString(accuracy)));
+ const auto geogSrcCRS =
+ dynamic_cast<crs::GeographicCRS *>(
+ model->interpolationCRS().get())
+ ? NN_NO_CHECK(model->interpolationCRS())
+ : sourceCRS->demoteTo2D(std::string(), dbContext)
+ ->promoteTo3D(std::string(), dbContext);
+ const auto vertCRSMetre =
+ axis->unit() == common::UnitOfMeasure::METRE &&
+ axis->direction() == cs::AxisDirection::UP
+ ? targetCRS
+ : util::nn_static_pointer_cast<crs::CRS>(
+ crs::VerticalCRS::create(
+ util::PropertyMap().set(
+ common::IdentifiedObject::NAME_KEY,
+ getNameVertCRSMetre(targetCRS->nameStr())),
+ vertDst->datum(), vertDst->datumEnsemble(),
+ cs::VerticalCS::createGravityRelatedHeight(
+ common::UnitOfMeasure::METRE)));
+ const auto properties = util::PropertyMap().set(
+ common::IdentifiedObject::NAME_KEY,
+ buildOpName("Transformation", vertCRSMetre, geogSrcCRS));
+
+ // Try to find a representative value for the accuracy of this grid
+ // from the registered transformations.
+ std::vector<metadata::PositionalAccuracyNNPtr> accuracies;
+ const auto &modelAccuracies =
+ model->coordinateOperationAccuracies();
+ if (modelAccuracies.empty()) {
+ if (authFactory) {
+ const auto transformationsForGrid =
+ io::DatabaseContext::getTransformationsForGridName(
+ authFactory->databaseContext(), projFilename);
+ double accuracy = -1;
+ for (const auto &transf : transformationsForGrid) {
+ accuracy = std::max(accuracy, getAccuracy(transf));
+ }
+ if (accuracy >= 0) {
+ accuracies.emplace_back(
+ metadata::PositionalAccuracy::create(
+ toString(accuracy)));
+ }
}
}
- }
- return Transformation::createGravityRelatedHeightToGeographic3D(
- properties, vertCRSMetre, geogSrcCRS, nullptr, projFilename,
- !modelAccuracies.empty() ? modelAccuracies : accuracies);
- };
+ return Transformation::createGravityRelatedHeightToGeographic3D(
+ properties, vertCRSMetre, geogSrcCRS, nullptr, projFilename,
+ !modelAccuracies.empty() ? modelAccuracies : accuracies);
+ };
std::vector<CoordinateOperationNNPtr> res;
const auto &authFactory = context.context->getAuthorityFactory();
@@ -3593,35 +3592,38 @@ void CoordinateOperationFactory::Private::
// NAD83 only exists in 2D version in EPSG, so if it has been
// promoted to 3D, when researching a vertical to geog
// transformation, try to down cast to 2D.
- const auto geog3DToVertTryThroughGeog2D = [&res, &context](
- const crs::GeographicCRS *geogSrcIn, const crs::VerticalCRS *vertDstIn,
- const crs::CRSNNPtr &targetCRSIn) {
- if (res.empty() && geogSrcIn && vertDstIn &&
- geogSrcIn->coordinateSystem()->axisList().size() == 3) {
- const auto &authFactory = context.context->getAuthorityFactory();
- const auto dbContext =
- authFactory ? authFactory->databaseContext().as_nullable()
- : nullptr;
- const auto candidatesSrcGeod(findCandidateGeodCRSForDatum(
- authFactory, geogSrcIn,
- geogSrcIn->datumNonNull(dbContext).get()));
- for (const auto &candidate : candidatesSrcGeod) {
- auto geogCandidate =
- util::nn_dynamic_pointer_cast<crs::GeographicCRS>(
- candidate);
- if (geogCandidate &&
- geogCandidate->coordinateSystem()->axisList().size() == 2) {
- bool ignored;
- res =
- findOpsInRegistryDirect(NN_NO_CHECK(geogCandidate),
- targetCRSIn, context, ignored);
- break;
+ const auto geog3DToVertTryThroughGeog2D =
+ [&res, &context](const crs::GeographicCRS *geogSrcIn,
+ const crs::VerticalCRS *vertDstIn,
+ const crs::CRSNNPtr &targetCRSIn) {
+ if (res.empty() && geogSrcIn && vertDstIn &&
+ geogSrcIn->coordinateSystem()->axisList().size() == 3) {
+ const auto &authFactory =
+ context.context->getAuthorityFactory();
+ const auto dbContext =
+ authFactory ? authFactory->databaseContext().as_nullable()
+ : nullptr;
+ const auto candidatesSrcGeod(findCandidateGeodCRSForDatum(
+ authFactory, geogSrcIn,
+ geogSrcIn->datumNonNull(dbContext).get()));
+ for (const auto &candidate : candidatesSrcGeod) {
+ auto geogCandidate =
+ util::nn_dynamic_pointer_cast<crs::GeographicCRS>(
+ candidate);
+ if (geogCandidate &&
+ geogCandidate->coordinateSystem()->axisList().size() ==
+ 2) {
+ bool ignored;
+ res = findOpsInRegistryDirect(
+ NN_NO_CHECK(geogCandidate), targetCRSIn, context,
+ ignored);
+ break;
+ }
}
+ return true;
}
- return true;
- }
- return false;
- };
+ return false;
+ };
if (geog3DToVertTryThroughGeog2D(geogSrc, vertDst, targetCRS)) {
// do nothing
@@ -5169,26 +5171,27 @@ crs::CRSNNPtr CRS::getResolvedCRS(const crs::CRSNNPtr &crs,
// Even if they aren't equivalent, we update extentOut with the one of the
// identified CRS if our input one is absent/not reliable.
- const auto tryToIdentifyByName = [&crs, &name, &authFactory, approxExtent,
- &extentOut](
- io::AuthorityFactory::ObjectType objectType) {
- if (name != "unknown" && name != "unnamed") {
- auto matches = authFactory->createObjectsFromName(
- name, {objectType}, false, 2);
- if (matches.size() == 1) {
- const auto match =
- util::nn_static_pointer_cast<crs::CRS>(matches.front());
- if (approxExtent || !extentOut) {
- extentOut = operation::getExtent(match);
- }
- if (match->isEquivalentTo(
- crs.get(), util::IComparable::Criterion::EQUIVALENT)) {
- return match;
+ const auto tryToIdentifyByName =
+ [&crs, &name, &authFactory, approxExtent,
+ &extentOut](io::AuthorityFactory::ObjectType objectType) {
+ if (name != "unknown" && name != "unnamed") {
+ auto matches = authFactory->createObjectsFromName(
+ name, {objectType}, false, 2);
+ if (matches.size() == 1) {
+ const auto match =
+ util::nn_static_pointer_cast<crs::CRS>(matches.front());
+ if (approxExtent || !extentOut) {
+ extentOut = operation::getExtent(match);
+ }
+ if (match->isEquivalentTo(
+ crs.get(),
+ util::IComparable::Criterion::EQUIVALENT)) {
+ return match;
+ }
}
}
- }
- return crs;
- };
+ return crs;
+ };
auto geogCRS = dynamic_cast<crs::GeographicCRS *>(crs.get());
if (geogCRS && authFactory) {