aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2019-02-18 09:45:18 +0100
committerGitHub <noreply@github.com>2019-02-18 09:45:18 +0100
commit4277e15cefae5bb1d49312498e0f626b652e7524 (patch)
tree189e5bc87ac99a73f515b3800c2e1898c732f7b3
parent455cb889e8259d8799f4cc9cce6b06ebe076f363 (diff)
parente8b2e2a36324006146406fb1fc89ce6ed863807f (diff)
downloadPROJ-4277e15cefae5bb1d49312498e0f626b652e7524.tar.gz
PROJ-4277e15cefae5bb1d49312498e0f626b652e7524.zip
Merge pull request #1276 from rouault/intermediate_crs_use_only_if_no_direct_transformation
Modify the default strategy of researching intermediate CRS to do it only if there is no direct transformation
-rw-r--r--docs/source/apps/projinfo.rst11
-rw-r--r--include/proj/coordinateoperation.hpp17
-rw-r--r--include/proj/crs.hpp7
-rw-r--r--src/apps/projinfo.cpp50
-rw-r--r--src/iso19111/c_api.cpp44
-rw-r--r--src/iso19111/coordinateoperation.cpp36
-rw-r--r--src/iso19111/crs.cpp9
-rw-r--r--src/proj.h15
-rw-r--r--test/unit/test_c_api.cpp4
-rw-r--r--test/unit/test_crs.cpp66
-rw-r--r--test/unit/test_factory.cpp3
-rw-r--r--test/unit/test_operation.cpp14
12 files changed, 191 insertions, 85 deletions
diff --git a/docs/source/apps/projinfo.rst b/docs/source/apps/projinfo.rst
index cbfd44d4..af9ed171 100644
--- a/docs/source/apps/projinfo.rst
+++ b/docs/source/apps/projinfo.rst
@@ -21,7 +21,7 @@ Synopsis
| [--spatial-test contains|intersects]
| [--crs-extent-use none|both|intersection|smallest]
| [--grid-check none|discard_missing|sort] [--show-superseded]
- | [--pivot-crs none|{auth:code[,auth:code]*}]
+ | [--pivot-crs always|if_no_direct_transformation|never|{auth:code[,auth:code]*}]
| [--boundcrs-to-wgs84]
| [--main-db-path path] [--aux-db-path path]*
| [--identify]
@@ -157,13 +157,16 @@ The following control parameters can appear in any order:
.. note:: only used for coordinate operation computation
-.. option:: --pivot-crs none|{auth:code[,auth:code]*}
+.. option:: --pivot-crs always|if_no_direct_transformation|never|{auth:code[,auth:code]*}
Determine if intermediate (pivot) CRS can be used when researching coordinate
operation between 2 CRS. A typical example is the WGS84 pivot. By default,
- projinfo will consider any potential pivot. If using the ``none`` strategy,
+ projinfo will consider any potential pivot if there is no direct transformation
+ ( ``if_no_direct_transformation``). If using the ``never`` strategy,
only direct transformations between the source and target CRS will be
- used. It is also possible to restrict the pivot CRS to consider by specifying
+ used. If using the ``always`` strategy, intermediate CRS will be considered
+ even if there are direct transformations.
+ It is also possible to restrict the pivot CRS to consider by specifying
one or several CRS by their AUTHORITY:CODE.
.. note:: only used for coordinate operation computation
diff --git a/include/proj/coordinateoperation.hpp b/include/proj/coordinateoperation.hpp
index 6b32e24d..92b655f9 100644
--- a/include/proj/coordinateoperation.hpp
+++ b/include/proj/coordinateoperation.hpp
@@ -1726,9 +1726,22 @@ class PROJ_GCC_DLL CoordinateOperationContext {
PROJ_DLL GridAvailabilityUse getGridAvailabilityUse() const;
- PROJ_DLL void setAllowUseIntermediateCRS(bool use);
+ /** Describe if and how intermediate CRS should be used */
+ enum class IntermediateCRSUse {
+ /** Always search for intermediate CRS. */
+ ALWAYS,
- PROJ_DLL bool getAllowUseIntermediateCRS() const;
+ /** Only attempt looking for intermediate CRS if there is no direct
+ * transformation available. */
+ IF_NO_DIRECT_TRANSFORMATION,
+
+ /* Do not attempt looking for intermediate CRS. */
+ NEVER,
+ };
+
+ PROJ_DLL void setAllowUseIntermediateCRS(IntermediateCRSUse use);
+
+ PROJ_DLL IntermediateCRSUse getAllowUseIntermediateCRS() const;
PROJ_DLL void
setIntermediateCRS(const std::vector<std::pair<std::string, std::string>>
diff --git a/include/proj/crs.hpp b/include/proj/crs.hpp
index 6a09ea78..fb34d3b7 100644
--- a/include/proj/crs.hpp
+++ b/include/proj/crs.hpp
@@ -92,9 +92,10 @@ class PROJ_GCC_DLL CRS : public common::ObjectUsage {
PROJ_DLL GeodeticCRSPtr extractGeodeticCRS() const;
PROJ_DLL GeographicCRSPtr extractGeographicCRS() const;
PROJ_DLL VerticalCRSPtr extractVerticalCRS() const;
- PROJ_DLL CRSNNPtr
- createBoundCRSToWGS84IfPossible(const io::DatabaseContextPtr &dbContext,
- bool allowIntermediateCRS) const;
+ PROJ_DLL CRSNNPtr createBoundCRSToWGS84IfPossible(
+ const io::DatabaseContextPtr &dbContext,
+ operation::CoordinateOperationContext::IntermediateCRSUse
+ allowIntermediateCRSUse) const;
PROJ_DLL CRSNNPtr stripVerticalComponent() const;
PROJ_DLL const BoundCRSPtr &canonicalBoundCRS() PROJ_PURE_DECL;
diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp
index 29cf5fc3..9f908c8a 100644
--- a/src/apps/projinfo.cpp
+++ b/src/apps/projinfo.cpp
@@ -88,8 +88,8 @@ static void usage() {
<< " [--grid-check none|discard_missing|sort] "
"[--show-superseded]"
<< std::endl
- << " [--pivot-crs none|{auth:code[,auth:code]*}]"
- << std::endl
+ << " [--pivot-crs always|if_no_direct_transformation|"
+ << "never|{auth:code[,auth:code]*}]" << std::endl
<< " [--boundcrs-to-wgs84]" << std::endl
<< " [--main-db-path path] [--aux-db-path path]*"
<< std::endl
@@ -139,7 +139,7 @@ static std::string c_ify_string(const std::string &str) {
static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext,
const std::string &user_string,
bool kindIsCRS, const std::string &context,
- bool buildBoundCRSToWGS84, bool allowPivots,
+ bool buildBoundCRSToWGS84, CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS,
bool quiet) {
BaseObjectPtr obj;
@@ -213,7 +213,7 @@ static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext,
if (buildBoundCRSToWGS84) {
auto crs = std::dynamic_pointer_cast<CRS>(obj);
if (crs) {
- obj = crs->createBoundCRSToWGS84IfPossible(dbContext, allowPivots)
+ obj = crs->createBoundCRSToWGS84IfPossible(dbContext, allowUseIntermediateCRS)
.as_nullable();
}
}
@@ -224,7 +224,7 @@ static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext,
// ---------------------------------------------------------------------------
static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj,
- bool allowPivots, const OutputOptions &outputOpt) {
+ CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS, const OutputOptions &outputOpt) {
auto identified = dynamic_cast<const IdentifiedObject *>(obj.get());
if (!outputOpt.quiet && identified && identified->isDeprecated()) {
@@ -272,7 +272,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj,
objToExport =
nn_dynamic_pointer_cast<IPROJStringExportable>(
crs->createBoundCRSToWGS84IfPossible(dbContext,
- allowPivots));
+ allowUseIntermediateCRS));
}
if (!objToExport) {
objToExport = projStringExportable;
@@ -412,7 +412,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj,
if (crs) {
objToExport = nn_dynamic_pointer_cast<IWKTExportable>(
crs->createBoundCRSToWGS84IfPossible(dbContext,
- allowPivots));
+ allowUseIntermediateCRS));
}
if (!objToExport) {
objToExport = wktExportable;
@@ -516,12 +516,14 @@ static void outputOperations(
CoordinateOperationContext::SpatialCriterion spatialCriterion,
CoordinateOperationContext::SourceTargetCRSExtentUse crsExtentUse,
CoordinateOperationContext::GridAvailabilityUse gridAvailabilityUse,
- bool allowPivots,
+ CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS,
const std::vector<std::pair<std::string, std::string>> &pivots,
const std::string &authority, bool usePROJGridAlternatives,
bool showSuperseded, const OutputOptions &outputOpt, bool summary) {
auto sourceObj = buildObject(dbContext, sourceCRSStr, true, "source CRS",
- false, false, outputOpt.quiet);
+ false,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER,
+ outputOpt.quiet);
auto sourceCRS = nn_dynamic_pointer_cast<CRS>(sourceObj);
if (!sourceCRS) {
std::cerr << "source CRS string is not a CRS" << std::endl;
@@ -529,7 +531,9 @@ static void outputOperations(
}
auto targetObj = buildObject(dbContext, targetCRSStr, true, "target CRS",
- false, false, outputOpt.quiet);
+ false,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER,
+ outputOpt.quiet);
auto targetCRS = nn_dynamic_pointer_cast<CRS>(targetObj);
if (!targetCRS) {
std::cerr << "target CRS string is not a CRS" << std::endl;
@@ -548,7 +552,7 @@ static void outputOperations(
ctxt->setSpatialCriterion(spatialCriterion);
ctxt->setSourceAndTargetCRSExtentUse(crsExtentUse);
ctxt->setGridAvailabilityUse(gridAvailabilityUse);
- ctxt->setAllowUseIntermediateCRS(allowPivots);
+ ctxt->setAllowUseIntermediateCRS(allowUseIntermediateCRS);
ctxt->setIntermediateCRS(pivots);
ctxt->setUsePROJAlternativeGridNames(usePROJGridAlternatives);
ctxt->setDiscardSuperseded(!showSuperseded);
@@ -560,7 +564,7 @@ static void outputOperations(
std::exit(1);
}
if (outputOpt.quiet && !list.empty()) {
- outputObject(dbContext, list[0], allowPivots, outputOpt);
+ outputObject(dbContext, list[0], allowUseIntermediateCRS, outputOpt);
return;
}
if (summary) {
@@ -586,7 +590,7 @@ static void outputOperations(
}
outputOperationSummary(op);
std::cout << std::endl;
- outputObject(dbContext, op, allowPivots, outputOpt);
+ outputObject(dbContext, op, allowUseIntermediateCRS, outputOpt);
}
}
}
@@ -617,7 +621,8 @@ int main(int argc, char **argv) {
bool buildBoundCRSToWGS84 = false;
CoordinateOperationContext::GridAvailabilityUse gridAvailabilityUse =
CoordinateOperationContext::GridAvailabilityUse::USE_FOR_SORTING;
- bool allowPivots = true;
+ CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS =
+ CoordinateOperationContext::IntermediateCRSUse::IF_NO_DIRECT_TRANSFORMATION;
std::vector<std::pair<std::string, std::string>> pivots;
bool usePROJGridAlternatives = true;
std::string mainDBPath;
@@ -814,8 +819,15 @@ int main(int argc, char **argv) {
} else if (arg == "--pivot-crs" && i + 1 < argc) {
i++;
auto value(argv[i]);
- if (ci_equal(std::string(value), "none")) {
- allowPivots = false;
+ if (ci_equal(std::string(value), "always")) {
+ allowUseIntermediateCRS =
+ CoordinateOperationContext::IntermediateCRSUse::ALWAYS;
+ } else if (ci_equal(std::string(value), "if_no_direct_transformation")) {
+ allowUseIntermediateCRS =
+ CoordinateOperationContext::IntermediateCRSUse::IF_NO_DIRECT_TRANSFORMATION;
+ } else if (ci_equal(std::string(value), "never")) {
+ allowUseIntermediateCRS =
+ CoordinateOperationContext::IntermediateCRSUse::NEVER;
} else {
auto splitValue(split(value, ','));
for (const auto &v : splitValue) {
@@ -915,7 +927,7 @@ int main(int argc, char **argv) {
if (!user_string.empty()) {
auto obj(buildObject(dbContext, user_string, kindIsCRS, "input string",
- buildBoundCRSToWGS84, allowPivots,
+ buildBoundCRSToWGS84, allowUseIntermediateCRS,
outputOpt.quiet));
if (guessDialect) {
auto dialect = WKTParser().guessDialect(user_string);
@@ -933,7 +945,7 @@ int main(int argc, char **argv) {
}
std::cout << std::endl;
}
- outputObject(dbContext, obj, allowPivots, outputOpt);
+ outputObject(dbContext, obj, allowUseIntermediateCRS, outputOpt);
if (identify) {
auto crs = dynamic_cast<CRS *>(obj.get());
if (crs) {
@@ -1043,7 +1055,7 @@ int main(int argc, char **argv) {
outputOperations(
dbContext, sourceCRSStr, targetCRSStr, bboxFilter, spatialCriterion,
- crsExtentUse, gridAvailabilityUse, allowPivots, pivots, authority,
+ crsExtentUse, gridAvailabilityUse, allowUseIntermediateCRS, pivots, authority,
usePROJGridAlternatives, showSuperseded, outputOpt, summary);
}
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp
index 79732bab..b3f200fe 100644
--- a/src/iso19111/c_api.cpp
+++ b/src/iso19111/c_api.cpp
@@ -1475,7 +1475,8 @@ PJ *proj_crs_create_bound_crs(PJ_CONTEXT *ctx, const PJ *base_crs,
* @param options null-terminated list of options, or NULL. Currently
* supported options are:
* <ul>
- * <li>ALLOW_INTERMEDIATE_CRS=YES/NO. Defaults to NO. When set to YES,
+ * <li>ALLOW_INTERMEDIATE_CRS=ALWAYS/IF_NO_DIRECT_TRANSFORMATION/NEVER. Defaults
+ * to NEVER. When set to ALWAYS/IF_NO_DIRECT_TRANSFORMATION,
* intermediate CRS may be considered when computing the possible
* transformations. Slower.</li>
* </ul>
@@ -1493,11 +1494,18 @@ PJ *proj_crs_create_bound_crs_to_WGS84(PJ_CONTEXT *ctx, const PJ *crs,
}
auto dbContext = getDBcontextNoException(ctx, __FUNCTION__);
try {
- bool allowIntermediateCRS = false;
+ CoordinateOperationContext::IntermediateCRSUse allowIntermediateCRS =
+ CoordinateOperationContext::IntermediateCRSUse::NEVER;
for (auto iter = options; iter && iter[0]; ++iter) {
const char *value;
if ((value = getOptionValue(*iter, "ALLOW_INTERMEDIATE_CRS="))) {
- allowIntermediateCRS = ci_equal(value, "YES");
+ if (ci_equal(value, "YES") || ci_equal(value, "ALWAYS")) {
+ allowIntermediateCRS =
+ CoordinateOperationContext::IntermediateCRSUse::ALWAYS;
+ } else if (ci_equal(value, "IF_NO_DIRECT_TRANSFORMATION")) {
+ allowIntermediateCRS = CoordinateOperationContext::
+ IntermediateCRSUse::IF_NO_DIRECT_TRANSFORMATION;
+ }
} else {
std::string msg("Unknown option :");
msg += *iter;
@@ -6378,22 +6386,36 @@ void proj_operation_factory_context_set_use_proj_alternative_grid_names(
* The current implementation is limited to researching one intermediate
* step.
*
- * By default, all potential C candidates will be used.
- * proj_operation_factory_context_set_allowed_intermediate_crs()
- * can be used to restrict them.
- *
- * The default is true.
+ * By default, with the IF_NO_DIRECT_TRANSFORMATION stratgey, all potential
+ * C candidates will be used if there is no direct tranformation.
*
* @param ctx PROJ context, or NULL for default context
* @param factory_ctx Operation factory context. must not be NULL
- * @param allow whether intermediate CRS may be used.
+ * @param use whether and how intermediate CRS may be used.
*/
void proj_operation_factory_context_set_allow_use_intermediate_crs(
- PJ_CONTEXT *ctx, PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, int allow) {
+ PJ_CONTEXT *ctx, PJ_OPERATION_FACTORY_CONTEXT *factory_ctx,
+ PROJ_INTERMEDIATE_CRS_USE use) {
SANITIZE_CTX(ctx);
assert(factory_ctx);
try {
- factory_ctx->operationContext->setAllowUseIntermediateCRS(allow != 0);
+ switch (use) {
+ case PROJ_INTERMEDIATE_CRS_USE_ALWAYS:
+ factory_ctx->operationContext->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::ALWAYS);
+ break;
+
+ case PROJ_INTERMEDIATE_CRS_USE_IF_NO_DIRECT_TRANSFORMATION:
+ factory_ctx->operationContext->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::
+ IF_NO_DIRECT_TRANSFORMATION);
+ break;
+
+ case PROJ_INTERMEDIATE_CRS_USE_NEVER:
+ factory_ctx->operationContext->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::NEVER);
+ break;
+ }
} catch (const std::exception &e) {
proj_log_error(ctx, __FUNCTION__, e.what());
}
diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp
index d964cdc1..2128124b 100644
--- a/src/iso19111/coordinateoperation.cpp
+++ b/src/iso19111/coordinateoperation.cpp
@@ -9242,7 +9242,8 @@ struct CoordinateOperationContext::Private {
bool usePROJNames_ = true;
GridAvailabilityUse gridAvailabilityUse_ =
GridAvailabilityUse::USE_FOR_SORTING;
- bool allowUseIntermediateCRS_ = true;
+ IntermediateCRSUse allowUseIntermediateCRS_ = CoordinateOperationContext::
+ IntermediateCRSUse::IF_NO_DIRECT_TRANSFORMATION;
std::vector<std::pair<std::string, std::string>>
intermediateCRSAuthCodes_{};
bool discardSuperseded_ = true;
@@ -9436,18 +9437,17 @@ CoordinateOperationContext::getGridAvailabilityUse() const {
*
* Concretely if in the database there is an operation from A to C
* (or C to A), and another one from C to B (or B to C), but no direct
- * operation between A and B, setting this parameter to true, allow
- * chaining both operations.
+ * operation between A and B, setting this parameter to
+ * ALWAYS/IF_NO_DIRECT_TRANSFORMATION, allow chaining both operations.
*
* The current implementation is limited to researching one intermediate
* step.
*
- * By default, all potential C candidates will be used. setIntermediateCRS()
- * can be used to restrict them.
- *
- * The default is true.
+ * By default, with the IF_NO_DIRECT_TRANSFORMATION stratgey, all potential
+ * C candidates will be used if there is no direct tranformation.
*/
-void CoordinateOperationContext::setAllowUseIntermediateCRS(bool use) {
+void CoordinateOperationContext::setAllowUseIntermediateCRS(
+ IntermediateCRSUse use) {
d->allowUseIntermediateCRS_ = use;
}
@@ -9458,12 +9458,13 @@ void CoordinateOperationContext::setAllowUseIntermediateCRS(bool use) {
*
* Concretely if in the database there is an operation from A to C
* (or C to A), and another one from C to B (or B to C), but no direct
- * operation between A and B, setting this parameter to true, allow
- * chaining both operations.
+ * operation between A and B, setting this parameter to
+ * ALWAYS/IF_NO_DIRECT_TRANSFORMATION, allow chaining both operations.
*
- * The default is true.
+ * The default is IF_NO_DIRECT_TRANSFORMATION.
*/
-bool CoordinateOperationContext::getAllowUseIntermediateCRS() const {
+CoordinateOperationContext::IntermediateCRSUse
+CoordinateOperationContext::getAllowUseIntermediateCRS() const {
return d->allowUseIntermediateCRS_;
}
@@ -10401,9 +10402,6 @@ findOpsInRegistryDirect(const crs::CRSNNPtr &sourceCRS,
static std::vector<CoordinateOperationNNPtr> findsOpsInRegistryWithIntermediate(
const crs::CRSNNPtr &sourceCRS, const crs::CRSNNPtr &targetCRS,
const CoordinateOperationContextNNPtr &context) {
- if (!context->getAllowUseIntermediateCRS()) {
- return std::vector<CoordinateOperationNNPtr>();
- }
const auto &authFactory = context->getAuthorityFactory();
assert(authFactory);
@@ -11215,7 +11213,13 @@ CoordinateOperationFactory::Private::createOperations(
// NAD27 to NAD83 has tens of results already. No need to look
// for a pivot
- if (res.size() < 5 || getenv("PROJ_FORCE_SEARCH_PIVOT")) {
+ if ((res.empty() &&
+ context.context->getAllowUseIntermediateCRS() ==
+ CoordinateOperationContext::IntermediateCRSUse::
+ IF_NO_DIRECT_TRANSFORMATION) ||
+ context.context->getAllowUseIntermediateCRS() ==
+ CoordinateOperationContext::IntermediateCRSUse::ALWAYS ||
+ getenv("PROJ_FORCE_SEARCH_PIVOT")) {
auto resWithIntermediate = findsOpsInRegistryWithIntermediate(
sourceCRS, targetCRS, context.context);
res.insert(res.end(), resWithIntermediate.begin(),
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp
index ebbed7a1..01a588e3 100644
--- a/src/iso19111/crs.cpp
+++ b/src/iso19111/crs.cpp
@@ -375,9 +375,10 @@ VerticalCRSPtr CRS::extractVerticalCRS() const {
*
* @return a CRS.
*/
-CRSNNPtr
-CRS::createBoundCRSToWGS84IfPossible(const io::DatabaseContextPtr &dbContext,
- bool allowIntermediateCRS) const {
+CRSNNPtr CRS::createBoundCRSToWGS84IfPossible(
+ const io::DatabaseContextPtr &dbContext,
+ operation::CoordinateOperationContext::IntermediateCRSUse
+ allowIntermediateCRSUse) const {
auto thisAsCRS = NN_NO_CHECK(
std::static_pointer_cast<CRS>(shared_from_this().as_nullable()));
auto boundCRS = util::nn_dynamic_pointer_cast<BoundCRS>(thisAsCRS);
@@ -442,7 +443,7 @@ CRS::createBoundCRSToWGS84IfPossible(const io::DatabaseContextPtr &dbContext,
authority == "any" ? std::string() : authority);
auto ctxt = operation::CoordinateOperationContext::create(
authFactory, extent, 0.0);
- ctxt->setAllowUseIntermediateCRS(allowIntermediateCRS);
+ ctxt->setAllowUseIntermediateCRS(allowIntermediateCRSUse);
// ctxt->setSpatialCriterion(
// operation::CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION);
auto list =
diff --git a/src/proj.h b/src/proj.h
index f25c3228..af22c341 100644
--- a/src/proj.h
+++ b/src/proj.h
@@ -629,6 +629,19 @@ typedef enum {
PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION
} PROJ_SPATIAL_CRITERION;
+ /** Describe if and how intermediate CRS should be used */
+typedef enum {
+ /** Always search for intermediate CRS. */
+ PROJ_INTERMEDIATE_CRS_USE_ALWAYS,
+
+ /** Only attempt looking for intermediate CRS if there is no direct
+ * transformation available. */
+ PROJ_INTERMEDIATE_CRS_USE_IF_NO_DIRECT_TRANSFORMATION,
+
+ /* Do not attempt looking for intermediate CRS. */
+ PROJ_INTERMEDIATE_CRS_USE_NEVER,
+} PROJ_INTERMEDIATE_CRS_USE;
+
/** Type of coordinate system. */
typedef enum
{
@@ -906,7 +919,7 @@ void PROJ_DLL proj_operation_factory_context_set_use_proj_alternative_grid_names
void PROJ_DLL proj_operation_factory_context_set_allow_use_intermediate_crs(
PJ_CONTEXT *ctx,
PJ_OPERATION_FACTORY_CONTEXT *factory_ctx,
- int allow);
+ PROJ_INTERMEDIATE_CRS_USE use);
void PROJ_DLL proj_operation_factory_context_set_allowed_intermediate_crs(
PJ_CONTEXT *ctx,
diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp
index 273a04e6..6205a9b8 100644
--- a/test/unit/test_c_api.cpp
+++ b/test/unit/test_c_api.cpp
@@ -1389,7 +1389,7 @@ TEST_F(CApi, proj_create_operations_with_pivot) {
ASSERT_NE(ctxt, nullptr);
ContextKeeper keeper_ctxt(ctxt);
proj_operation_factory_context_set_allow_use_intermediate_crs(
- m_ctxt, ctxt, false);
+ m_ctxt, ctxt, PROJ_INTERMEDIATE_CRS_USE_NEVER);
auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt);
ASSERT_NE(res, nullptr);
@@ -1444,6 +1444,8 @@ TEST_F(CApi, proj_create_operations_with_pivot) {
m_ctxt, ctxt, PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION);
proj_operation_factory_context_set_grid_availability_use(
m_ctxt, ctxt, PROJ_GRID_AVAILABILITY_IGNORED);
+ proj_operation_factory_context_set_allow_use_intermediate_crs(
+ m_ctxt, ctxt, PROJ_INTERMEDIATE_CRS_USE_ALWAYS);
auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt);
ASSERT_NE(res, nullptr);
diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp
index 26bcf621..4953529c 100644
--- a/test/unit/test_crs.cpp
+++ b/test/unit/test_crs.cpp
@@ -3436,8 +3436,12 @@ TEST(crs, boundCRS_crs_link) {
EXPECT_TRUE(baseCRS->isEquivalentTo(GeographicCRS::EPSG_4267.get()));
EXPECT_TRUE(baseCRS->canonicalBoundCRS() != nullptr);
- EXPECT_TRUE(baseCRS->createBoundCRSToWGS84IfPossible(nullptr, false)
- ->isEquivalentTo(baseCRS->canonicalBoundCRS().get()));
+ EXPECT_TRUE(
+ baseCRS
+ ->createBoundCRSToWGS84IfPossible(
+ nullptr,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER)
+ ->isEquivalentTo(baseCRS->canonicalBoundCRS().get()));
}
{
@@ -4725,27 +4729,35 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) {
auto factory = AuthorityFactory::create(dbContext, "EPSG");
{
auto crs_4326 = factory->createCoordinateReferenceSystem("4326");
- EXPECT_EQ(crs_4326->createBoundCRSToWGS84IfPossible(dbContext, false),
+ EXPECT_EQ(crs_4326->createBoundCRSToWGS84IfPossible(
+ dbContext,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER),
crs_4326);
}
{
auto crs_32631 = factory->createCoordinateReferenceSystem("32631");
- EXPECT_EQ(crs_32631->createBoundCRSToWGS84IfPossible(dbContext, false),
+ EXPECT_EQ(crs_32631->createBoundCRSToWGS84IfPossible(
+ dbContext,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER),
crs_32631);
}
{
// Pulkovo 42 East Germany
auto crs_5670 = factory->createCoordinateReferenceSystem("5670");
- EXPECT_EQ(crs_5670->createBoundCRSToWGS84IfPossible(dbContext, false),
+ EXPECT_EQ(crs_5670->createBoundCRSToWGS84IfPossible(
+ dbContext,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER),
crs_5670);
}
{
// Pulkovo 42 Romania
auto crs_3844 = factory->createCoordinateReferenceSystem("3844");
- auto bound =
- crs_3844->createBoundCRSToWGS84IfPossible(dbContext, false);
+ auto bound = crs_3844->createBoundCRSToWGS84IfPossible(
+ dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER);
EXPECT_NE(bound, crs_3844);
- EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false),
+ EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(
+ dbContext,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER),
bound);
auto boundCRS = nn_dynamic_pointer_cast<BoundCRS>(bound);
ASSERT_TRUE(boundCRS != nullptr);
@@ -4759,10 +4771,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) {
{
// Pulkovo 42 Poland
auto crs_2171 = factory->createCoordinateReferenceSystem("2171");
- auto bound =
- crs_2171->createBoundCRSToWGS84IfPossible(dbContext, false);
+ auto bound = crs_2171->createBoundCRSToWGS84IfPossible(
+ dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER);
EXPECT_NE(bound, crs_2171);
- EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false),
+ EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(
+ dbContext,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER),
bound);
auto boundCRS = nn_dynamic_pointer_cast<BoundCRS>(bound);
ASSERT_TRUE(boundCRS != nullptr);
@@ -4776,10 +4790,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) {
{
// NTF (Paris)
auto crs_4807 = factory->createCoordinateReferenceSystem("4807");
- auto bound =
- crs_4807->createBoundCRSToWGS84IfPossible(dbContext, false);
+ auto bound = crs_4807->createBoundCRSToWGS84IfPossible(
+ dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER);
EXPECT_NE(bound, crs_4807);
- EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false),
+ EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(
+ dbContext,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER),
bound);
auto boundCRS = nn_dynamic_pointer_cast<BoundCRS>(bound);
ASSERT_TRUE(boundCRS != nullptr);
@@ -4791,10 +4807,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) {
{
// NTF (Paris) / Lambert zone II + NGF-IGN69 height
auto crs_7421 = factory->createCoordinateReferenceSystem("7421");
- auto bound =
- crs_7421->createBoundCRSToWGS84IfPossible(dbContext, false);
+ auto bound = crs_7421->createBoundCRSToWGS84IfPossible(
+ dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER);
EXPECT_NE(bound, crs_7421);
- EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false),
+ EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(
+ dbContext,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER),
bound);
auto boundCRS = nn_dynamic_pointer_cast<BoundCRS>(bound);
ASSERT_TRUE(boundCRS != nullptr);
@@ -4807,13 +4825,17 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) {
}
{
auto crs = createVerticalCRS();
- EXPECT_EQ(crs->createBoundCRSToWGS84IfPossible(dbContext, false), crs);
+ EXPECT_EQ(crs->createBoundCRSToWGS84IfPossible(
+ dbContext,
+ CoordinateOperationContext::IntermediateCRSUse::NEVER),
+ crs);
}
{
auto factoryIGNF =
AuthorityFactory::create(DatabaseContext::create(), "IGNF");
auto crs = factoryIGNF->createCoordinateReferenceSystem("TERA50STEREO");
- auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false);
+ auto bound = crs->createBoundCRSToWGS84IfPossible(
+ dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER);
EXPECT_NE(bound, crs);
auto boundCRS = nn_dynamic_pointer_cast<BoundCRS>(bound);
ASSERT_TRUE(boundCRS != nullptr);
@@ -4827,7 +4849,8 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) {
auto factoryIGNF =
AuthorityFactory::create(DatabaseContext::create(), "IGNF");
auto crs = factoryIGNF->createCoordinateReferenceSystem("PGP50");
- auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false);
+ auto bound = crs->createBoundCRSToWGS84IfPossible(
+ dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER);
EXPECT_NE(bound, crs);
auto boundCRS = nn_dynamic_pointer_cast<BoundCRS>(bound);
ASSERT_TRUE(boundCRS != nullptr);
@@ -4838,7 +4861,8 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) {
}
{
auto crs = factory->createCoordinateReferenceSystem("4269"); // NAD83
- auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false);
+ auto bound = crs->createBoundCRSToWGS84IfPossible(
+ dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER);
EXPECT_EQ(bound, crs);
}
}
diff --git a/test/unit/test_factory.cpp b/test/unit/test_factory.cpp
index d5c82afb..80de017f 100644
--- a/test/unit/test_factory.cpp
+++ b/test/unit/test_factory.cpp
@@ -1616,7 +1616,8 @@ class FactoryWithTmpDatabase : public ::testing::Test {
{
auto ctxt =
CoordinateOperationContext::create(factory, nullptr, 0);
- ctxt->setAllowUseIntermediateCRS(false);
+ ctxt->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::NEVER);
res = CoordinateOperationFactory::create()->createOperations(
srcCRS, targetCRS, ctxt);
EXPECT_EQ(res.size(), 1U);
diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp
index 344f79b7..90deb661 100644
--- a/test/unit/test_operation.cpp
+++ b/test/unit/test_operation.cpp
@@ -4185,7 +4185,8 @@ TEST(operation, geogCRS_to_geogCRS_context_default) {
auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0);
ctxt->setSpatialCriterion(
CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION);
- ctxt->setAllowUseIntermediateCRS(false);
+ ctxt->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::NEVER);
// Directly found in database
{
@@ -4241,7 +4242,8 @@ TEST(operation, geogCRS_to_geogCRS_context_match_by_name) {
auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0);
ctxt->setSpatialCriterion(
CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION);
- ctxt->setAllowUseIntermediateCRS(false);
+ ctxt->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::NEVER);
auto NAD27 = GeographicCRS::create(
PropertyMap().set(IdentifiedObject::NAME_KEY,
GeographicCRS::EPSG_4267->nameStr()),
@@ -4581,6 +4583,8 @@ TEST(operation, geogCRS_to_geogCRS_context_concatenated_operation) {
auto authFactory =
AuthorityFactory::create(DatabaseContext::create(), "EPSG");
auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0);
+ ctxt->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::ALWAYS);
auto list = CoordinateOperationFactory::create()->createOperations(
authFactory->createCoordinateReferenceSystem("4807"), // NTF(Paris)
authFactory->createCoordinateReferenceSystem("4171"), // RGF93
@@ -4644,6 +4648,8 @@ TEST(operation, geogCRS_to_geogCRS_CH1903_to_CH1903plus_context) {
auto authFactory =
AuthorityFactory::create(DatabaseContext::create(), "EPSG");
auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0);
+ ctxt->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::ALWAYS);
auto list = CoordinateOperationFactory::create()->createOperations(
authFactory->createCoordinateReferenceSystem("4149"), // CH1903
authFactory->createCoordinateReferenceSystem("4150"), // CH1903+
@@ -5127,6 +5133,8 @@ TEST(operation,
auto authFactory =
AuthorityFactory::create(DatabaseContext::create(), "EPSG");
auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0);
+ ctxt->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::ALWAYS);
auto list = CoordinateOperationFactory::create()->createOperations(
authFactory->createCoordinateReferenceSystem("4807"), // NTF(Paris)
authFactory->createCoordinateReferenceSystem("32631"), // UTM31 WGS84
@@ -6205,6 +6213,8 @@ TEST(operation, IGNF_LAMB1_TO_EPSG_4326) {
auto authFactory =
AuthorityFactory::create(DatabaseContext::create(), std::string());
auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0);
+ ctxt->setAllowUseIntermediateCRS(
+ CoordinateOperationContext::IntermediateCRSUse::ALWAYS);
auto list = CoordinateOperationFactory::create()->createOperations(
AuthorityFactory::create(DatabaseContext::create(), "IGNF")
->createCoordinateReferenceSystem("LAMB1"),