Skip to content

Fix pj_obj_create() grid alternative resolution when old_proj_grid_name is NULL#4701

Merged
rouault merged 1 commit intoOSGeo:masterfrom
phaarnes:fix/pj_obj_create-grid-alternative-resolution
Mar 7, 2026
Merged

Fix pj_obj_create() grid alternative resolution when old_proj_grid_name is NULL#4701
rouault merged 1 commit intoOSGeo:masterfrom
phaarnes:fix/pj_obj_create-grid-alternative-resolution

Conversation

@phaarnes
Copy link
Copy Markdown
Contributor

@phaarnes phaarnes commented Mar 6, 2026

The commit changed pj_obj_create() to pass nullptr as the database context to PROJStringFormatter::create(), which prevents substitutePROJAlternativeGridNames() from resolving grid names via the grid_alternatives table. The reson for the change was to add support for that plain pipeline strings should work without a proj.db.

Example: proj_create_from_database("EPSG","9484") returns a pipeline with the original grid name href2008a.bin instead of the CDN name no_kv_href2008a.tif, causing downstream failures.

Fix: Use the database context if it is already open (e.g. when called from proj_create_from_database), but do not open it otherwise — preserving the original intent of 63c491e that plain pipeline strings work without proj.db.

…olution

When pj_obj_create() exports a coordinate operation to a PROJ string, it
previously passed nullptr as the database context to PROJStringFormatter.
This prevented substitutePROJAlternativeGridNames() from resolving grid
names via the grid_alternatives table.

For grid transformations where old_proj_grid_name is NULL (153 entries in
the standard PROJ database), the file-level fallback (getProjGridName)
cannot resolve the grid because it queries old_proj_grid_name. Only
lookForGridAlternative (which queries original_grid_name) can resolve
these grids, but it requires a database context.

This change adds getDatabaseContextIfOpen() to projCppContext, which
returns the cached database context if already opened (e.g. from a prior
proj_create_from_database call), without attempting to open proj.db.
This preserves the original intent of commit 63c491e that callers
using plain pipeline strings can run without proj.db.

Adds a test for EPSG:9484 (grid href2008a.bin -> no_kv_href2008a.tif)
which has a NULL old_proj_grid_name.
@rouault rouault added the backport 9.8 Backport to 9.8 branch label Mar 7, 2026
@rouault rouault merged commit 459bb0d into OSGeo:master Mar 7, 2026
30 checks passed
@phaarnes phaarnes deleted the fix/pj_obj_create-grid-alternative-resolution branch March 9, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 9.8 Backport to 9.8 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pj_obj_create() regression: grid_alternatives not resolved in PROJ 9.8.0

2 participants