Skip to content

Commit 9393831

Browse files
committed
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 OSGeo/gdal#3470, this helps decreasing the time of proj_create_crs_to_crs() from 18 ms to 10 ms.
1 parent 6293c43 commit 9393831

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/iso19111/factory.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4243,6 +4243,22 @@ AuthorityFactory::createFromCRSCodesWithIntermediates(
42434243
return listTmp;
42444244
}
42454245

4246+
const auto CheckIfHasOperations = [=](const std::string &auth_name,
4247+
const std::string &code) {
4248+
return !(d->run("SELECT 1 FROM coordinate_operation_view WHERE "
4249+
"(source_crs_auth_name = ? AND source_crs_code = ?) OR "
4250+
"(target_crs_auth_name = ? AND target_crs_code = ?)",
4251+
{auth_name, code, auth_name, code})
4252+
.empty());
4253+
};
4254+
4255+
// If the source or target CRS are not the source or target of an operation,
4256+
// do not run the next costly requests.
4257+
if (!CheckIfHasOperations(sourceCRSAuthName, sourceCRSCode) ||
4258+
!CheckIfHasOperations(targetCRSAuthName, targetCRSCode)) {
4259+
return listTmp;
4260+
}
4261+
42464262
const std::string sqlProlog(
42474263
discardSuperseded
42484264
?

0 commit comments

Comments
 (0)