aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-03-18 15:18:48 +0100
committerEven Rouault <even.rouault@spatialys.com>2021-03-18 16:04:44 +0100
commit9393831dce0ca5271834caa32dc93ab48aca0c2c (patch)
treec8f1b94de17fbd0eba69ead99be092caf028701a
parent6293c434c6d86cc672dee969d6cf6bcd07945237 (diff)
downloadPROJ-9393831dce0ca5271834caa32dc93ab48aca0c2c.tar.gz
PROJ-9393831dce0ca5271834caa32dc93ab48aca0c2c.zip
createFromCRSCodesWithIntermediates(): improve perf when no match
createFromCRSCodesWithIntermediates() runs a rather costly self-join. Only run it if the source and target CRS are the source/target of a coordinate operation. This helps for the performance of proj_create_crs_to_crs() when run on projected CRS for example that are extremely unlikely to be the source/target of an operation (except currently the Finish ones). For the EPSG:26915 to EPSG:3857 case of https://github.com/OSGeo/gdal/issues/3470, this helps decreasing the time of proj_create_crs_to_crs() from 18 ms to 10 ms.
-rw-r--r--src/iso19111/factory.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp
index 5da9e6e0..ee882b4c 100644
--- a/src/iso19111/factory.cpp
+++ b/src/iso19111/factory.cpp
@@ -4243,6 +4243,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
?