diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 421cdb8817..1ec741e131 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -6081,6 +6081,22 @@ AuthorityFactory::createFromCRSCodesWithIntermediates( return listTmp; } + const auto CheckIfHasOperations = [=](const std::string &auth_name, + const std::string &code) { + return !(d->run("SELECT 1 FROM coordinate_operation_view WHERE " + "(source_crs_auth_name = ? AND source_crs_code = ?) OR " + "(target_crs_auth_name = ? AND target_crs_code = ?)", + {auth_name, code, auth_name, code}) + .empty()); + }; + + // If the source or target CRS are not the source or target of an operation, + // do not run the next costly requests. + if (!CheckIfHasOperations(sourceCRSAuthName, sourceCRSCode) || + !CheckIfHasOperations(targetCRSAuthName, targetCRSCode)) { + return listTmp; + } + const std::string sqlProlog( discardSuperseded ?