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.5k stars 2.99k forks source link

Error in "Clip Raster by Mask Layer" tool #50801

Closed stuskier closed 1 year ago

stuskier commented 1 year ago

What is the bug or the crash?

When using the Clip Raster by Mask Layer tool with the Keep resolution of input raster option selected, the output raster is shifted diagonally by approximately 0.4 pixels. The shift error does not occur when the option is unchecked.

Steps to reproduce the issue

  1. Load a raster and a vector polygon layer into QGIS, both using the same CRS (in my case, EPSG:2927).
  2. Run the Clip Raster by Mask Layer tool, using the vector polygon layer as the Mask Layer.
  3. Click the Keep resolution of input raster option on.
  4. Compare the tool output raster to the input raster. The output is offset diagonally approximately 0.4 pixel.
  5. Note that this offset error does not happen when the Keep resolution of input raster option is not selected.

Versions

QGIS version | 3.28.0-Firenze | QGIS code revision | ed3ad0430f3 -- | -- | -- | -- Qt version | 5.15.3 Python version | 3.9.5 GDAL/OGR version | 3.5.2 PROJ version | 9.1.0 EPSG Registry database version | v10.074 (2022-08-01) GEOS version | 3.10.3-CAPI-1.16.1 SQLite version | 3.39.4 PDAL version | 2.4.3 PostgreSQL client version | unknown SpatiaLite version | 5.0.1 QWT version | 6.1.6 QScintilla2 version | 2.13.1 OS version | Windows 10 Version 2009   |   |   |   Active Python plugins DataPlotly | 3.9.2 DissolveWithStats | 0.6 GroupStats | 2.2.6 ImportPhotos | 3.0.4 joinmultiplelines | Version 0.4.1 LAStools | 1.4 latlontools | 3.6.6 mapswipetool_plugin | 1.2 mask | 1.10.2 mmqgis | 2021.9.10 MultiDistanceBuffer | 3.2.4 nextgis_connect | 0.14.0 NNJoin | 3.1.3 OSMDownloader | 1.0.3 pointstopaths | 0.4 qchainage | 3.0.1 Qgis2threejs | 2.7.1 QGISSortAndNumber-master | 1.0 qgis_resource_sharing | 1.0.0 quick_map_services | 0.19.32 RasterAttributeTable | 1.2 SemiAutomaticClassificationPlugin | 7.10.8 Serval | 3.10.5 shapetools | 3.4.9 SpreadsheetLayers | 2.1.0-alpha1 SRTM-Downloader | 3.1.17 SuperLabeling | ver.1.4 VectorBender | 0.2.1 db_manager | 0.1.20 MetaSearch | 0.3.6 processing | 2.12.99 sagaprovider | 2.12.99 QGIS version 3.28.0-Firenze QGIS code revision [ed3ad0430f3](https://github.com/qgis/QGIS/commit/ed3ad0430f3) Qt version 5.15.3 Python version 3.9.5 GDAL/OGR version 3.5.2 PROJ version 9.1.0 EPSG Registry database version v10.074 (2022-08-01) GEOS version 3.10.3-CAPI-1.16.1 SQLite version 3.39.4 PDAL version 2.4.3 PostgreSQL client version unknown SpatiaLite version 5.0.1 QWT version 6.1.6 QScintilla2 version 2.13.1 OS version Windows 10 Version 2009 Active Python plugins DataPlotly 3.9.2 DissolveWithStats 0.6 GroupStats 2.2.6 ImportPhotos 3.0.4 joinmultiplelines Version 0.4.1 LAStools 1.4 latlontools 3.6.6 mapswipetool_plugin 1.2 mask 1.10.2 mmqgis 2021.9.10 MultiDistanceBuffer 3.2.4 nextgis_connect 0.14.0 NNJoin 3.1.3 OSMDownloader 1.0.3 pointstopaths 0.4 qchainage 3.0.1 Qgis2threejs 2.7.1 QGISSortAndNumber-master 1.0 qgis_resource_sharing 1.0.0 quick_map_services 0.19.32 RasterAttributeTable 1.2 SemiAutomaticClassificationPlugin 7.10.8 Serval 3.10.5 shapetools 3.4.9 SpreadsheetLayers 2.1.0-alpha1 SRTM-Downloader 3.1.17 SuperLabeling ver.1.4 VectorBender 0.2.1 db_manager 0.1.20 MetaSearch 0.3.6 processing 2.12.99 sagaprovider 2.12.99 ### Supported QGIS version - [X] I'm running a supported QGIS version according to the roadmap. ### New profile - [X] I tried with a new QGIS profile ### Additional context This bug may also be related to a Stack Exchange issue from 2016: [https://gis.stackexchange.com/questions/220380/offset-in-pixels-observed-in-outputted-raster-when-clip-raster-by-mask-layer-o](url)
nicogodet commented 1 year ago

Please see https://github.com/OSGeo/gdal/issues/5430 and https://github.com/qgis/QGIS/issues/47715

Not a QGIS issue, closing.

stuskier commented 1 year ago

I respectfully disagree, this IS a QGIS problem! Here's why: QGIS is providing users with a tool that does NOT generate the expected output. Furthermore, the user has no idea that a shift in the output raster will take place.

The discussions that have taken place in the issues that you refer to are further evidence that the "Keep resolution of input raster" is causing frustration. This option provides no useful function; it only causes confusion and wasted time.

At the very least - for the love of all that is good and just in this world - alert the user by adding the phrase "This will create offset pixels in the output raster".

Simply pointing to GDALWARP is not a solution; it only perpetuates a problem.

nicogodet commented 1 year ago

This is the purpose of the second issue I linked.

Current description can cause frustration and this would benefit a rephrase.

I can point you where it is in the code if needed.