Skip to content

Commit

Permalink
Merge pull request #3662 from OSGeo/backport-3661-to-9.2
Browse files Browse the repository at this point in the history
[Backport 9.2] [Performance regression fix] Fix slowness on proj_trans() on WGS 84 <--> NAD83 conversions
  • Loading branch information
rouault committed Mar 11, 2023
2 parents 1bb2656 + c7f93e2 commit 1ef29f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/4D_api.cpp
Expand Up @@ -307,8 +307,7 @@ int pj_get_suggested_operation(PJ_CONTEXT *,
!opList[iBest].isPriorityOp)) &&
!alt.isOffshore)) {

if (skipNonInstantiable &&
!proj_coordoperation_is_instantiable(alt.pj->ctx, alt.pj)) {
if (skipNonInstantiable && !alt.isInstantiable()) {
continue;
}
iBest = i;
Expand All @@ -320,6 +319,16 @@ int pj_get_suggested_operation(PJ_CONTEXT *,
return iBest;
}

//! @cond Doxygen_Suppress
/**************************************************************************************/
bool PJCoordOperation::isInstantiable() const {
/**************************************************************************************/
if (isInstantiableCached == INSTANTIABLE_STATUS_UNKNOWN)
isInstantiableCached = proj_coordoperation_is_instantiable(pj->ctx, pj);
return bool(isInstantiableCached);
}
//! @endcond

/**************************************************************************************/
static void warnAboutMissingGrid(PJ *P)
/**************************************************************************************/
Expand Down Expand Up @@ -2100,7 +2109,7 @@ PJ *proj_create_crs_to_crs_from_pj(PJ_CONTEXT *ctx, const PJ *source_crs,
!foundInstanciableAndNonBallpark) {
if (!proj_coordoperation_has_ballpark_transformation(op.pj->ctx,
op.pj) &&
proj_coordoperation_is_instantiable(op.pj->ctx, op.pj)) {
op.isInstantiable()) {
foundInstanciableAndNonBallpark = true;
}
}
Expand Down Expand Up @@ -2432,7 +2441,7 @@ PJ_PROJ_INFO proj_pj_info(PJ *P) {
// If there's just a single coordinate operation which is
// instanciable, use it.
for (const auto &op : P->alternativeCoordinateOperations) {
if (proj_coordoperation_is_instantiable(op.pj->ctx, op.pj)) {
if (op.isInstantiable()) {
if (candidateOp == nullptr) {
candidateOp = op.pj;
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/proj_internal.h
Expand Up @@ -316,6 +316,7 @@ typedef void (*PJ_OPERATOR)(PJ_COORD &, PJ *);
#define PJD_WGS84 4 /* WGS84 (or anything considered equivalent) */

struct PJCoordOperation {
public:
int idxInOriginalList;
double minxSrc = 0.0;
double minySrc = 0.0;
Expand Down Expand Up @@ -390,6 +391,13 @@ struct PJCoordOperation {
}

~PJCoordOperation() { proj_destroy(pj); }

bool isInstantiable() const;

private:
static constexpr int INSTANTIABLE_STATUS_UNKNOWN =
-1; // must be different from 0(=false) and 1(=true)
mutable int isInstantiableCached = INSTANTIABLE_STATUS_UNKNOWN;
};

enum class TMercAlgo {
Expand Down

0 comments on commit 1ef29f0

Please sign in to comment.