Skip to content

Comments

r.pack: Store all CRS info in the file#6408

Merged
wenzeslaus merged 1 commit intoOSGeo:mainfrom
wenzeslaus:store-all-proj-info-in-raster-pack
Sep 26, 2025
Merged

r.pack: Store all CRS info in the file#6408
wenzeslaus merged 1 commit intoOSGeo:mainfrom
wenzeslaus:store-all-proj-info-in-raster-pack

Conversation

@wenzeslaus
Copy link
Member

The r.pack missed couple of the new PROJ-underscore files which are describing or defining the CRS (aka projection) at the project level. Specifically, projects created with EPSG have PROJ_SRID file (not PROJ_EPSG) which was previously omitted, and thus missing in the exported raster pack file. Additionally, the implementation missed another project-level information which is stored in and retrieved from the default computational region, namely projection and zone keys. The new code reads them with g.region and stores them in a JSON file inside the pack file.

The new tests check for the expected files and check the format and content of the newly added JSON file.

The r.pack missed couple of the new PROJ-underscore files which are describing or defining the CRS (aka projection) at the project level. Specifically, projects created with EPSG have PROJ_SRID file (not PROJ_EPSG) which was previously omitted, and thus missing in the exported raster pack file. Additionally, the implementation missed another project-level information which is stored in and retrieved from the default computational region, namely projection and zone keys. The new code reads them with g.region and stores them in a JSON file inside the pack file.

The new tests check for the expected files and check the format and content of the newly added JSON file.
@github-actions github-actions bot added raster Related to raster data processing Python Related code is in Python module tests Related to Test Suite labels Sep 25, 2025
@neteler neteler added this to the 8.5.0 milestone Sep 25, 2025
@wenzeslaus wenzeslaus merged commit 33c8e01 into OSGeo:main Sep 26, 2025
27 checks passed
@wenzeslaus wenzeslaus deleted the store-all-proj-info-in-raster-pack branch September 26, 2025 15:03
wenzeslaus added a commit that referenced this pull request Sep 30, 2025
The code for reading cell header (and computational region) used -1 as a default for zone (following example of the proj field). However, negative numbers are used to represent UTM south zones. On the other hand, 0 is used as a value for CRSs without zone (so everything else except UTM). So, this changes the default from -1 to 0. The code is reading internal GRASS data, and the writing code is setting the zone to 0, so -1 did not pop up anywhere based on the fact that zone is required by the code to be present (so -1 was either replaced or error was produced).

Core the context, the internal stograte is a custom key-value pair text file which uses 0. On the other hand, 'null' is available and used as a value in JSON outputs (#6407) and in r.pack computation region CRS JSON info which is implemented as a pass-through from the g.region JSON output (#6408 for original and #6407 for pass-through).

This does not have a specific test because in the overall integration only 0 is occuring (see above). The general functionality should be covered by g.region tests from #6407.
wenzeslaus added a commit that referenced this pull request Oct 1, 2025
This adds another parameter to create_project called pack which allows for creating a project from raster pack files (requires the recent fix from #6408 for the complete CRS info including the computational region addition). Additionally, it refactors general CRS string handling from grass.py so that the pack code is available in the command line, but also that the general handling is available in the Python API.

Because grass/script/core.py can't take any more code, the underlying code is in grass.grassdb.create. This includes both the new functions and refactored code (the code reuses pieces of the XY project creation). Tests are included for the create_project level and separate tests for the underlying grass.grassdb.create level. The new functions include private functions (some of them used in create_project) and public functions (but somewhat internal in grass.grassdb).

The new add/create region function uses the general terms used now in g.region JSON API (#6407), so it is less dependent on the keys in the internal region format.

As part of the refactoring, this moves handling of a general CRS string (aka geostring) from the main executable (grass.py) script to the library, so that library function has the one, universal parameter feature and the CLI has the pack without adding CLI specific code to support pack in CLI.

A new translatable intro error message is now produced in the command line when project creation fails to. The text serves as an into to whatever comes afterwards from the exception (e.g. GDAL output).

Similarly to the main grass.py CLI, this adds the CRS string parameter to the experimental subcommand run. Since the create_function now supports this universal, CLI-friendly way, the addition is just about passing the parameter from command line to the function, so it is easy to add with benefits mostly for testing at this point.

This is adding a separate fixture for grass.app which is the same as the one added to grass.script, but having the fixture at the grass package level interfered with session setups in the grass.app tests. The grass.app fixture is using grass.tools while the grass.script one is written with run_command, so that also makes them different and aligns well with grass.script not using the grass.tools API.

For tests of the subcommands, this uses the standard pytest output capturing fixture, but it also runs the same tests with the subcommand package to capture stdout on Windows in a more reliable way because otherwise srid is not in the JSON from g.proj in the test. We skip rather than xfail the capdf tests on Windows since the issues don't seem to be in our code since subprocess way works just fine, but we use subprocess on all platform for simplicity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants