tools: add --link and --out parameters for raster and vector files#7182
tools: add --link and --out parameters for raster and vector files#7182tangelll wants to merge 7 commits intoOSGeo:mainfrom
Conversation
|
Hi @wenzeslaus, 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? |
wenzeslaus
left a comment
There was a problem hiding this comment.
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.
| create_parser.add_argument( | ||
| "--link-raster", | ||
| action="append", | ||
| help="link a raster map to the project (can be used multiple times)", | ||
| ) |
There was a problem hiding this comment.
What would be the use case for these in a workflow?
python/grass/app/cli.py
Outdated
| run_subparser.add_argument( | ||
| "--link-raster", | ||
| type=str, | ||
| nargs="+", |
There was a problem hiding this comment.
This eats the "named arguments" unless used with =. Needs more config.
|
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. |
|
Yes, you can create a |
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.tiffwhich links (r.external) a raster file (same for vector and similarly for r.external.out).How to do:
I tested the raster linking functionality using the
ortho2010_t792_subset_20cm.tiffile from thenc_spm_08_grass7dataset, ensuring the map name matched the filename. For vector testing, I used the ne_110m_admin_0_countries dataset from Natural Earth as an external sample to verify the link process.https://www.naturalearthdata.com/downloads/110m-cultural-vectors/110m-admin-0-countries/
To run my commands succesfuly you need to ensure that these files are in your workplaces.
Before Start
Before starting the test, ensure that you have copied your updated cli.py to the GRASS installation directory.
For me (macOS m4):
To Test Image file
Result
| Type of Map: GDAL-link Number of Categories: 0 |
| Data Type: CELL Semantic label: (none) |
| Rows: 3750 |
| Columns: 3500 |
| Total Cells: 13125000 |
| Projection: x,y |
| N: 220750 S: 220000 Res: 0.2 |
| E: 639000 W: 638300 Res: 0.2 |
| Range of data: min = 0 max = 251 |
| |
| Data Source: |
| /Users/tangel/Works/grass/ortho2010_t792_subset_20cm.tif band 1 |
| |
| |
| Data Description: |
| generated by r.external |
| |
| Comments: |
| r.external -o input="ortho2010_t792_subset_20cm.tif" output="ortho20\ |
| 10_t792_subset_20cm"
To Test Map file
Result
OGR layer: ne_110m_admin_0_countries | 18:01 [260/653]
| OGR datasource: /Users/tangel/Downloads/ne_110m_admin_0_countries/ne_110m |
|
To Test Raster.out
You can change test folder name.
python3 -m grass.app run r.mapcalc "test_result = ortho2010_t792_subset_20cm.1" --link-raster=ortho2010_t792_subset_20cm.tif --out-raster=./test_salihResult
Over-riding projection check
Reading band 1 of 3...
Link to raster map <ortho2010_t792_subset_20cm.1> created.
Reading band 2 of 3...
Link to raster map <ortho2010_t792_subset_20cm.2> created.
Reading band 3 of 3...
Link to raster map <ortho2010_t792_subset_20cm.3> created.
Imagery group <ortho2010_t792_subset_20cm> created
ortho2010_t792_subset_20cm.1
ortho2010_t792_subset_20cm.2
ortho2010_t792_subset_20cm.3
100%
➜ grass git:(subcommand_cli) ✗ cd test_salih
➜ test_salih git:(subcommand_cli) ✗ ls
test_result
To Test Vector.out
Result
Over-riding projection check 19:20 [1/1404]
Building topology for vector map ne_110m_admin_0_countries@PERMANENT...
Using external data format 'ESRI Shapefile' (feature type 'polygon')
Registering primitives...
577 primitives registered
10654 vertices registered
v.external complete. Link to vector map <ne_110m_admin_0_countries>
created.
Current output format for vectors: GPKG
Layer/table: 1/ne_110m_admin_0_countries
type count min max
point 0 0 0
line 0 0 0
boundary 289 0 176
centroid 0 0 0
area 0 0 0
face 0 0 0
kernel 0 0 0
all 289 0 176
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