Skip to content

tools: add --link and --out parameters for raster and vector files#7182

Open
tangelll wants to merge 8 commits intoOSGeo:mainfrom
tangelll:subcommand_cli
Open

tools: add --link and --out parameters for raster and vector files#7182
tangelll wants to merge 8 commits intoOSGeo:mainfrom
tangelll:subcommand_cli

Conversation

@tangelll
Copy link
Copy Markdown

@tangelll tangelll commented Mar 14, 2026

This pr open for this issue :#7176

Description: 

There is a project in Grass Gsoc ideas list which name is Subcommand CLI for GRASS. I am being able to finish Add --link-raster=some/file.tiff which links (r.external) a raster file (same for vector and similarly for r.external.out). 

Before Start

Before starting the test, ensure that you have copied your updated cli.py to the GRASS installation directory.

For me (macOS m4):

    cp cli.py /usr/local/grass85/etc/python/grass/app

Test

Run test_r_external.py under /r.external/testsuite

Result

Test For v.external under testsuite

Reading band -1 of 1...
ERROR 5: elevation.nc: GDALDataset::GetRasterBand(-1) - Illegal band #

ERROR: Selected band (-1) does not exist

Reading band 1 of 1...
Link to raster map <test_external_map> created.

Reading band 1 of 1...
Link to raster map <test_external_map> created.

Reading band 1 of 1...
Link to raster map <test_external_map> created.

Reading band 1 of 1...
Link to raster map <test_external_map> created.

ERROR 4: /Users/tangel/Works/grass/raster/r.external/testsuite/non_existent_file.tif: No such file or directory

Reading band 1 of 1...
Link to raster map <map_1> created.
Default region for this project updated
Region for the current mapset updated

Reading band 1 of 1...
Link to raster map <map_2> created.
Default region for this project updated
Region for the current mapset updated

Reading band 1 of 1...
Link to raster map <test_external_map> created.
Default region for this project updated
Region for the current mapset updated

Reading band 1 of 1...
Link to raster map <test_external_map> created.
Default region for this project updated
Region for the current mapset updated

Reading band 1 of 1...
Link to raster map <test_external_map> created.
Default region for this project updated
Region for the current mapset updated

Reading band 1 of 1...
Link to raster map <second_map> created.
Default region for this project updated
Region for the current mapset updated

Reading band 1 of 1...
Link to raster map <test_external_map> created.
Default region for this project updated
Region for the current mapset updated

No projection information available
Over-riding projection check
WARNING: Imagery group <test_external_map> already exists and will be
overwritten.
Reading band 1 of 5...
Link to raster map <test_external_map.1> created.
Reading band 2 of 5...
Link to raster map <test_external_map.2> created.
Reading band 3 of 5...
Link to raster map <test_external_map.3> created.
Reading band 4 of 5...
Link to raster map <test_external_map.4> created.
Reading band 5 of 5...
Link to raster map <test_external_map.5> created.
Imagery group <test_external_map> created

No projection information available
Over-riding projection check
WARNING: Imagery group <test_external_map> already exists and will be
overwritten.
Reading band 1 of 5...
Link to raster map <test_external_map.1> created.
Reading band 2 of 5...
Link to raster map <test_external_map.2> created.
Reading band 3 of 5...
Link to raster map <test_external_map.3> created.
Reading band 4 of 5...
Link to raster map <test_external_map.4> created.
Reading band 5 of 5...
Link to raster map <test_external_map.5> created.
Imagery group <test_external_map> created

No projection information available
Over-riding projection check
Reading band 2 of 5...
Link to raster map <test_external_map> created.
Ok

@github-actions github-actions bot added Python Related code is in Python libraries labels Mar 14, 2026
@tangelll tangelll changed the title add subcommand for --link-raster r.external: add subcommand for vector, raster file and r.external.out Mar 14, 2026
@tangelll tangelll changed the title r.external: add subcommand for vector, raster file and r.external.out cli: add --link and --out parameters for raster and vector files to 'run' tool Mar 14, 2026
@tangelll tangelll changed the title cli: add --link and --out parameters for raster and vector files to 'run' tool tools: add --link and --out parameters for raster and vector files Mar 15, 2026
@tangelll
Copy link
Copy Markdown
Author

tangelll commented Mar 17, 2026

Hi @wenzeslaus,
I've been working on the Subcommand CLI for GRASS and would love to know if I'm heading in the right direction.

I have successfully implemented a 'one-step' execution flow where a user can link external data, run a module, and save the output externally in a single command.

It currently handles:

r.external / v.external linking before execution.

r.external.out / v.external.out for direct external output.

Does this align with the vision for CLI, or should I adjust the approach before moving further into the --region and import/export tasks?

Copy link
Copy Markdown
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

This needs more testing and a deeper analysis. What happens when you use the command twice in a same project (with --project)? How are multiple parameters and parameter interactions handled?

Also, this completely misses tests which are explicitly mentioned in the GSoC idea.

Comment thread python/grass/app/cli.py
Comment on lines +270 to +274
create_parser.add_argument(
"--link-raster",
action="append",
help="link a raster map to the project (can be used multiple times)",
)
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.

What would be the use case for these in a workflow?

Comment thread python/grass/app/cli.py Outdated
run_subparser.add_argument(
"--link-raster",
type=str,
nargs="+",
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.

This eats the "named arguments" unless used with =. Needs more config.

@tangelll
Copy link
Copy Markdown
Author

tangelll commented Mar 29, 2026

I would like to confirm if my testing methodology is on the right track. I noticed that there is currently no testsuite folder under v.external. Should I go ahead and create a new testsuite directory and add my test files there? Once I have your approval on this structure, I will proceed with the rest of the tests.

@github-actions github-actions bot added raster Related to raster data processing module tests Related to Test Suite labels Mar 29, 2026
@echoix
Copy link
Copy Markdown
Member

echoix commented Mar 29, 2026

Yes, you can create a testsuite folder for a gunittest-based test, or test folder for pytest-based test

@tangelll
Copy link
Copy Markdown
Author

Yes, you can create a testsuite folder for a gunittest-based test, or test folder for pytest-based test

After reading v.external.md, I decided not to add a testsuite because v.external is difficult to test reliably with existing GRASS testing mechanisms, and I chose to focus on revising my existing changes instead. Could you please start my Github workflow?

@tangelll tangelll changed the title tools: add --link and --out parameters for raster and vector files CLI: add --link and --out parameters for raster and vector files Apr 19, 2026
@tangelll tangelll changed the title CLI: add --link and --out parameters for raster and vector files tools: add --link and --out parameters for raster and vector files Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries 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