qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.52k stars 2.99k forks source link

Batch processing: Clip raster by mask layer (GDAL) #49147

Closed RMRubert closed 2 years ago

RMRubert commented 2 years ago

What is the bug or the crash?

QGIS adds the Y resolution with a - that makes the batch file not to run because there is no option -2.0. See the code shows -tr 2.0 -2.0 when I think it should be -tr 2.0 2.0.

`GDAL command: gdalwarp -overwrite -s_srs EPSG:7856 -t_srs EPSG:7856 -of -tr 2.0 -2.0 -tap -cutline F:/path_to_raster/Clean_raster.shp -cl Clean_raster -crop_to_cutline F:/path_to_raster/Differences_wd.asc F:\path_to_raster\Differences_wd GDAL command output: Process returned error code 1 ERROR 6: Unknown option name '-2.0' Usage: gdalwarp [--help-general] [--formats] [-s_srs srs_def] [-t_srs srs_def] [-to "NAME=VALUE"] [-vshift | -novshift] [[-s_coord_epoch epoch] | [-t_coord_epoch epoch]] [-order n | -tps | -rpc | -geoloc] [-et err_threshold] [-refine_gcps tolerance [minimum_gcps]] [-te xmin ymin xmax ymax] [-tr xres yres] [-tap] [-ts width height] [-ovr level|AUTO|AUTO-n|NONE] [-wo "NAME=VALUE"] [-ot Byte/Int16/...] [-wt Byte/Int16] [-srcnodata "value [value...]"] [-dstnodata "value [value...]"] -dstalpha [-r resampling_method] [-wm memory_in_mb] [-multi] [-q] [-cutline datasource] [-cl layer] [-cwhere expression] [-csql statement] [-cblend dist_in_pixels] [-crop_to_cutline] [-if format] [-of format] [-co "NAME=VALUE"] [-overwrite] [-nomd] [-cvmd meta_conflict_value] [-setci] [-oo NAME=VALUE] [-doo NAME=VALUE] srcfile dstfile

Available resampling methods: near (default), bilinear, cubic, cubicspline, lanczos, average, rms, mode, max, min, med, Q1, Q3, sum. Algorithm Clip raster by mask layer correctly executed… Execution completed in 0.19 seconds Results: {'OUTPUT': 'F:\path_to_raster2\Differences_wd'}

Loading resulting layers Batch execution completed in 1.51 seconds`

Steps to reproduce the issue

Use the tool with two file (Raster ascii) and click on run

Versions

QGIS version 3.22.6-Białowieża QGIS code revision b6f33b1a Compiled against Qt 5.15.2 Running against Qt 5.15.3 Python version 3.9.5 Compiled against GDAL/OGR 3.4.2 Running against GDAL/OGR 3.4.3 PROJ version 9.0.0 EPSG Registry database version v10.054 (2022-02-13) GEOS version 3.10.2-CAPI-1.16.0 SQLite version 3.38.1 PDAL version 2.3.0 PostgreSQL client version 13.0 SpatiaLite version 5.0.1 QWT version 6.1.3 QScintilla2 version 2.11.5 OS version Windows 10 Version 2009

Active Python plugins AusMap 1.1 concavehull 2.0 icsm_ntv2_transformer 1.1.1 MapsPrinter 0.9 mmqgis 2021.9.10 profiletool 4.2.2 quick_map_services 0.19.29 tuflow 3.3 valuetool 3.0.15 db_manager 0.1.20 grassprovider 2.12.99 MetaSearch 0.3.5 processing 2.12.99 sagaprovider 2.12.99

Supported QGIS version

New profile

Additional context

No response

alexbruy commented 2 years ago

Please attache your files.

uclaros commented 2 years ago

It seems that if keep resolution of input rasters is checked, then y resolution in -tr can be negative

RMRubert commented 2 years ago

I can't really upload the files, I will try to make a mock up case in the following days. One thing I noticed is that my output layer name is name.asc-namecarryon.asc, and at some point GDAL was complaining that doesn't know how to write in a asc-namecarryon filetype.

agiudiceandrea commented 2 years ago

It seems to me the issue could be in gdalwarp -overwrite -s_srs EPSG:7856 -t_srs EPSG:7856 -of -tr 2.0 -2.0 where the -of option is not followed by the format (given that the extension is missing in the output path "F:\path_to_raster\Differences_wd", so the parsing of the following other options is messed up...

agiudiceandrea commented 2 years ago

@alexbruy the underlying issue is due to the fact that if the filename contains a period, such as name.asc-namecarryon.asc, then the extension is incorrectly evaluated in QgsProcessingProvider::isSupportedOutputValue() as .asc-namecarryon.asc instead of .asc. This is due to the use of QFileInfo::completeSuffix() ("The complete suffix consists of all characters in the file after (but not including) the first '.'") instead of QFileInfo::suffix() ("The suffix consists of all characters in the file after (but not including) the last '.'") in QgsProcessingUtils::parseDestinationString() for output vector layers here https://github.com/qgis/QGIS/blob/597e8eebd47fedc9b9fc7278cce08ef79384b53d/src/core/processing/qgsprocessingutils.cpp#L755 and here https://github.com/qgis/QGIS/blob/597e8eebd47fedc9b9fc7278cce08ef79384b53d/src/core/processing/qgsprocessingutils.cpp#L761 and in QgsProcessingProvider::isSupportedOutputValue() for output raster layer here https://github.com/qgis/QGIS/blob/597e8eebd47fedc9b9fc7278cce08ef79384b53d/src/core/processing/qgsprocessingprovider.cpp#L185 and for pointcloud here https://github.com/qgis/QGIS/blob/597e8eebd47fedc9b9fc7278cce08ef79384b53d/src/core/processing/qgsprocessingprovider.cpp#L196

agiudiceandrea commented 2 years ago

@alexbruy, anyway, I think a check should be added in https://github.com/qgis/QGIS/blob/597e8eebd47fedc9b9fc7278cce08ef79384b53d/python/plugins/processing/algs/gdal/ClipRasterByMask.py#L211-L212 in order to avoid to add the -of option if the format is not recognized.

agiudiceandrea commented 2 years ago

@RMRubert how did you manage to insert an output file path as "F:\path_to_raster\Differences_wd" or "name.asc-namecarryon.asc" in the tool GUI and still be able to run the algorithm from the GUI? It seems to me the algorithm GUI prevents to run the algorithm if the output file path misses or has an unrecognized extension (the GUI displays the error " ... files are not supported as outputs for this algorithm").

RMRubert commented 2 years ago

I had the layers loaded in the QGIS so I did a dropdown to select each one. Then for the output I use this formula which is the only way that I know to copy the name of the layer into the output.

output > Calculate by expression > concat('F:\\Project\\Drawings\\BLA\\BLA2\\BLA3\\09_cleandata\\',layer_property(@INPUT, 'name'))

And then click run.

And the name of the file is: "Diff_SITE_EVENT_TIME_PATTERN_TIDE_SCENARIO_CELL_v07_d_Max.asc-Diff_SITE_EVENT_TIME_PATTERN_TIDE_SCENARIO_CELL_v07_d_Max.asc"

I don't particularly like having the .asc in the name but I haven't been able to filter it with the tools I have at the moment.

RMRubert commented 2 years ago

temp.zip

I can confirm the error happens if I add this command in the output as an expression concat('C:\\Users\\RMRub\\Desktop\\temp\\',layer_property(@INPUT, 'name')) but no error happens if I use concat('C:\\Users\\RMRub\\Desktop\\temp\\',layer_property(@INPUT, 'name'),'.asc') in any of the three rasters.

github-actions[bot] commented 2 years ago

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale". If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue. In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue. If there is no further activity on this issue, it will be closed in a week.

github-actions[bot] commented 2 years ago

While we hate to see this happen, this issue has been automatically closed because it has not had any activity in the last 42 days despite being marked as feedback. If this issue should be reconsidered, please follow the guidelines in the previous comment and reopen this issue. Or, if you have any further questions, there are also further support channels that can help you.

agiudiceandrea commented 2 years ago

@gioman , I think the Feedback label should be removed.

gioman commented 2 years ago

@gioman , I think the Feedback label should be removed.

reopened.