Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoTIFF grid reading: perf improvements (fixes #2785) #2787

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions include/proj/internal/lru_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ class Cache {
keys_.splice(keys_.begin(), keys_, iter->second);
return iter->second->value;
}

/**
* The const reference returned here is only
* guaranteed to be valid till the next insert/delete
*/
const Value* getPtr(const Key& k) {
Guard g(lock_);
const auto iter = cache_.find(k);
if (iter == cache_.end()) {
return nullptr;
}
keys_.splice(keys_.begin(), keys_, iter->second);
return &(iter->second->value);
}

/**
* returns a copy of the stored object (if found)
*/
Expand Down
56 changes: 31 additions & 25 deletions src/fwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
#define OUTPUT_UNITS P->right


static PJ_COORD fwd_prepare (PJ *P, PJ_COORD coo) {
static void fwd_prepare (PJ *P, PJ_COORD& coo) {
if (HUGE_VAL==coo.v[0] || HUGE_VAL==coo.v[1] || HUGE_VAL==coo.v[2])
return proj_coord_error ();
{
coo = proj_coord_error ();
return;
}

/* The helmert datum shift will choke unless it gets a sensible 4D coordinate */
if (HUGE_VAL==coo.v[2] && P->helmert) coo.v[2] = 0.0;
Expand All @@ -56,13 +59,15 @@ static PJ_COORD fwd_prepare (PJ *P, PJ_COORD coo) {
{
proj_log_error(P, _("Invalid latitude"));
proj_errno_set (P, PROJ_ERR_COORD_TRANSFM_INVALID_COORD);
return proj_coord_error ();
coo = proj_coord_error ();
return;
}
if (coo.lp.lam > 10 || coo.lp.lam < -10)
{
proj_log_error(P, _("Invalid longitude"));
proj_errno_set (P, PROJ_ERR_COORD_TRANSFM_INVALID_COORD);
return proj_coord_error ();
coo = proj_coord_error ();
return;
}


Expand All @@ -89,7 +94,7 @@ static PJ_COORD fwd_prepare (PJ *P, PJ_COORD coo) {
coo = proj_trans (P->cart, PJ_INV, coo); /* Go back to angular using local ellps */
}
if (coo.lp.lam==HUGE_VAL)
return coo;
return;
if (P->vgridshift)
coo = proj_trans (P->vgridshift, PJ_FWD, coo); /* Go orthometric from geometric */

Expand All @@ -100,18 +105,18 @@ static PJ_COORD fwd_prepare (PJ *P, PJ_COORD coo) {
if (0==P->over)
coo.lp.lam = adjlon(coo.lp.lam);

return coo;
return;
}


/* We do not support gridshifts on cartesian input */
if (INPUT_UNITS==PJ_IO_UNITS_CARTESIAN && P->helmert)
return proj_trans (P->helmert, PJ_INV, coo);
return coo;
coo = proj_trans (P->helmert, PJ_INV, coo);
return;
}


static PJ_COORD fwd_finalize (PJ *P, PJ_COORD coo) {
static void fwd_finalize (PJ *P, PJ_COORD& coo) {

switch (OUTPUT_UNITS) {

Expand Down Expand Up @@ -161,29 +166,28 @@ static PJ_COORD fwd_finalize (PJ *P, PJ_COORD coo) {

if (P->axisswap)
coo = proj_trans (P->axisswap, PJ_FWD, coo);

return coo;
}


static PJ_COORD error_or_coord(PJ *P, PJ_COORD coord, int last_errno) {
if (proj_errno(P))
static inline PJ_COORD error_or_coord(PJ *P, PJ_COORD coord, int last_errno) {
if (P->ctx->last_errno)
return proj_coord_error();

proj_errno_restore(P, last_errno);
P->ctx->last_errno = last_errno;

return coord;
}


PJ_XY pj_fwd(PJ_LP lp, PJ *P) {
int last_errno;
PJ_COORD coo = {{0,0,0,0}};
coo.lp = lp;

last_errno = proj_errno_reset(P);
const int last_errno = P->ctx->last_errno;
P->ctx->last_errno = 0;

if (!P->skip_fwd_prepare)
coo = fwd_prepare (P, coo);
fwd_prepare (P, coo);
if (HUGE_VAL==coo.v[0] || HUGE_VAL==coo.v[1])
return proj_coord_error ().xy;

Expand All @@ -202,22 +206,22 @@ PJ_XY pj_fwd(PJ_LP lp, PJ *P) {
return proj_coord_error ().xy;

if (!P->skip_fwd_finalize)
coo = fwd_finalize (P, coo);
fwd_finalize (P, coo);

return error_or_coord(P, coo, last_errno).xy;
}



PJ_XYZ pj_fwd3d(PJ_LPZ lpz, PJ *P) {
int last_errno;
PJ_COORD coo = {{0,0,0,0}};
coo.lpz = lpz;

last_errno = proj_errno_reset(P);
const int last_errno = P->ctx->last_errno;
P->ctx->last_errno = 0;

if (!P->skip_fwd_prepare)
coo = fwd_prepare (P, coo);
fwd_prepare (P, coo);
if (HUGE_VAL==coo.v[0])
return proj_coord_error ().xyz;

Expand All @@ -236,18 +240,20 @@ PJ_XYZ pj_fwd3d(PJ_LPZ lpz, PJ *P) {
return proj_coord_error ().xyz;

if (!P->skip_fwd_finalize)
coo = fwd_finalize (P, coo);
fwd_finalize (P, coo);

return error_or_coord(P, coo, last_errno).xyz;
}



PJ_COORD pj_fwd4d (PJ_COORD coo, PJ *P) {
int last_errno = proj_errno_reset(P);

const int last_errno = P->ctx->last_errno;
P->ctx->last_errno = 0;

if (!P->skip_fwd_prepare)
coo = fwd_prepare (P, coo);
fwd_prepare (P, coo);
if (HUGE_VAL==coo.v[0])
return proj_coord_error ();

Expand All @@ -266,7 +272,7 @@ PJ_COORD pj_fwd4d (PJ_COORD coo, PJ *P) {
return proj_coord_error ();

if (!P->skip_fwd_finalize)
coo = fwd_finalize (P, coo);
fwd_finalize (P, coo);

return error_or_coord(P, coo, last_errno);
}
Loading