Skip to content

init: add support any PROJ spatial reference ID with -c - #8254

Open
neteler wants to merge 7 commits into
OSGeo:mainfrom
neteler:add_authority_code_support
Open

neteler wants to merge 7 commits into
OSGeo:mainfrom
neteler:add_authority_code_support

Conversation

@neteler

@neteler neteler commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

This PR exposes the already existing support for authority:code to the command line interface. So far, create_project() only understood EPSG:... or an existing georeferenced file. Any other authority:code string (e.g. ESRI:102022) was treated as a filename.

With this PR, python/grass/script/core.py (create_project) now treats any -c/crs value that is not an existing path as a PROJ spatial reference ID and passes it straight through as g.proj srid=<value>.

This exposes the existing g.proj srid= capability through grass -c .... Existing georeferenced files are still read as georeferenced sources, and EPSG:code[:datum_trans] is kept for compatibility (GRASS custom syntax).

Details

  • python/grass/script/core.py (create_project): treat any -c value that is not an existing path as PROJ spatial reference ID and pass it straight through as g.proj srid=<value>. Existing files are still read as georeferenced sources, and EPSG:code[:datum_trans] keeps its existing behavior.
  • Docs: lib/init/grass.md/grass.html: synopsis and flags now use -c spatial_reference_id and point to https://proj.org/en/stable/apps/projinfo.html for supported definitions; --tmp-project help text updated accordingly.
  • Tests: unit tests for ESRI:102022 success and invalid ID failure; CLI regression tests confirming grass -c ESRI:102022 ... -e creates the project and grass -c EPSG:999999 ... -e exits non-zero with no traceback.

Example

grass -c ESRI:102022 ~/grassdata/my_area/
Starting GRASS...
Creating new GRASS project <my_area>...

                   __________  ___   __________
                  / ____/ __ \/   | / ___/ ___/
                 / / __/ /_/ / /| | \__ \\_  \
                / /_/ / _, _/ ___ |___/ /__/ /
                \____/_/ |_/_/  |_/____/____/

Welcome to GRASS 8.6.0dev (88f4ac5790)
[...]

Tests

  • pytest python/grass/script/tests/grass_script_core_location_test.py extended with test_crs_parameter_authority_code_syntax() and test_crs_parameter_invalid_id.

Disclosure: AI-assisted (Deepseek Flash model) - used for implementing the improvements, verified and tested by me.

This PR exposes the already existing support for `authority:code` to the command line interface.
So far, `create_project()` only understood `EPSG:...` or an existing georeferenced file. Any
other `authority:code` string (e.g. `ESRI:102022`) was treated as a filename

With this PR, `python/grass/script/core.py` (`create_project()`) now treats any `-c`/`crs` value
that isn't an existing path as an `authority:code` and passes it straight through as `g.proj srid=<value>`.
Like this, it exposes the existing `g.proj srid=` capability (which already handled e.g. `ESRI:102022`)
through `grass -c ...`. Existing georeferenced files and `EPSG:code[:datum_trans]` keep their current behavior.

**Details**

- `python/grass/script/core.py` (`create_project`): treat any `-c` value that is not an existing
  path as an `authority:code` and pass it straight through as `g.proj srid=<value>`. Existing
  files are still read as georeferenced sources, and `EPSG:code[:datum_trans]` keeps its
  existing behavior (including datum transform handling). This exposes the `g.proj srid=`
  capability through the start script/startup code.
- Docs: `lib/init/grass.md`/`grass.html` synopsis, flag, and example updated.
- Tests: unit tests for `ESRI:102022` success and invalid authority failure; CLI regression tests
  confirming `grass -c ESRI:102022 ... -e` creates the project and `grass -c EPSG:999999 ... -e`
  exits non-zero with no traceback.

**Tests**

- `pytest python/grass/script/tests/grass_script_core_location_test.py` extended
   with `test_crs_parameter_authority_code()` and `test_crs_parameter_invalid_authority_code`
@neteler neteler added this to the 8.6.0 milestone Nov 24, 2026
@neteler neteler added enhancement New feature or request Python Related code is in Python labels Nov 24, 2026
@neteler
neteler requested a review from metzm November 24, 2026 13:37
@github-actions github-actions Bot added HTML Related code is in HTML libraries docs markdown Related to markdown, markdown files tests Related to Test Suite labels Nov 24, 2026
Comment thread python/grass/script/core.py Resolved
Comment thread lib/init/grass.html Resolved
Comment thread lib/init/grass.html Resolved
Comment thread python/grass/script/core.py Resolved
@metzm

metzm commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Examples for accepted authority name:authority code combinations:

  • EPSG:4326
  • ESRI:102022
  • IAU:1000
  • IGNF:AMANU49
  • NKG:ETRF00
  • OGC:CRS27

neteler and others added 2 commits November 24, 2026 22:58
Co-authored-by: Markus Metz <33666869+metzm@users.noreply.github.com>

@wenzeslaus wenzeslaus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also for shortening the doc. I think EPSG items can be replaced by the new SRS/CRS ID in the doc.

Comment thread lib/init/grass.html Resolved
Comment thread lib/init/grass.html Resolved
@neteler

neteler commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Updates in e4929e5:

Implementation

  • python/grass/script/core.py: no more regex; anything non-file straight passes to g.proj srid=. (i.e., PROJ handling)

  • lib/init/grass.md and lib/init/grass.html: synopsis and flags now use -c spatial_reference_id instead of -c AUTHORITY:code; the separate -c EPSG:code and -c AUTHORITY:code flag blocks are removed (covered by spatial_reference_id); -c EPSG:code:datum_trans kept as GRASS custom syntax. All point to https://proj.org/en/stable/apps/projinfo.html for supported definitions. ESRI example updated accordingly.

  • lib/init/grass.py: --tmp-project help text/usage updated to "PROJ spatial reference ID":

grass --help 
GRASS 8.6.0dev
Geographic Resources Analysis Support System (GRASS).

Usage:
  grass [-h | --help] [-v | --version]
          [-c | -c geofile | -c EPSG:code[:datum_trans] | -c XY]
          [-e] [-f] [--text | --gtext | --gui] [--config param]
          [[[GISDBASE/]PROJECT/]MAPSET]
  grass [FLAG]... GISDBASE/PROJECT/MAPSET --exec EXECUTABLE [EPARAM]...
  grass --tmp-project [geofile | spatial_reference_id | XY] --exec EXECUTABLE [EPARAM]...
  grass --tmp-mapset GISDBASE/PROJECT/ --exec EXECUTABLE [EPARAM]...
[...]

Tests:

  • test_crs_parameter_authority_code → test_crs_parameter_authority_code_syntax
  • test_crs_parameter_invalid_authority_code → test_crs_parameter_invalid_id

@neteler
neteler requested a review from metzm November 26, 2026 13:34
@metzm

metzm commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

I have doubts about

-c EPSG:code:datum_trans kept as GRASS custom syntax

because some information on datum transformation requires not only a source datum, but also a target datum which is no longer by default WGS84. Thus the syntax EPSG:code:datum_trans does not make sense any more. Datum transformation during reprojection is in GRASS completely handled by PROJ. This datum_trans syntax is a left-over from PROJ4 days.

@metzm

metzm commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

[...] the syntax EPSG:code:datum_trans does not make sense any more. Datum transformation during reprojection is in GRASS completely handled by PROJ. This datum_trans syntax is a left-over from PROJ4 days.

This should be addressed in a separate PR also cleaning up g.proj and related library functions, please ignore for this PR.

@wenzeslaus wenzeslaus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks great.

Just be careful with commit message. I think the last comment doesn't fit 100% with the EPSG:xxxx:yyyy handling.

I agree with @metzm that EPSG:xxxx:yyyy is for a separate PR. One option there is to phase that so that it first creates a warning (let's say in 8.6.0 and after branching off 8.6, we remove it for 8.7, alternatively, we just announce at 8.6.0 and shift the removal down the line, so the actual removal would be 8.8).

@neteler

neteler commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Just be careful with commit message. I think the last comment doesn't fit 100% with the EPSG:xxxx:yyyy handling.

@wenzeslaus I am not 100% sure what you mean. Do you refer to the initial PR description? The rest is squashed anyway...

@wenzeslaus

Copy link
Copy Markdown
Member

In your recent comment, a bullet point says that anything non path goes as srid. That's the case for epsg, even without datum syntax, in the code.

Separately, a simple GH generated message usually doesn't describe the change well I would say.

@neteler neteler changed the title grass.py: add support for authority:code such as ESRI:xxxxxx grass.py: add support any PROJ spatial reference ID with -c Dec 3, 2026
@neteler

neteler commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

I have updated the PR description.

@neteler neteler changed the title grass.py: add support any PROJ spatial reference ID with -c init: add support any PROJ spatial reference ID with -c Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs enhancement New feature or request HTML Related code is in HTML libraries markdown Related to markdown, markdown files Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants