6

I am using QGIS tool "Clip raster by mask layer" in Processing Toolbox for clipping satellite(georeferenced) image raster using shape polygon with "clip to mask layer's extent" setting switched on.

I observed that the output clipped raster's pixels have an offset of around 0.5 pixel size with respect to source image.

Apparently there is a mistake in the algorithm of this tool especially while setting the Geotransform (which decides the positioning) of the output clipped raster.

How can I access the algorithm of this tool?

EDIT:

Found that the pycode ClipByMask.py is apparently (correct me if needed) not the code I am looking for, since it returns argument that calls other GDAL code. Below is the line that shows it:

return ['gdalwarp', GdalUtils.escapeAndJoin(arguments)]

Also observed that the pycode ClipByMask.py has following imports:

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm

from processing.algs.gdal.GdalUtils import GdalUtils

I was looking for the lines which contain geotransform[0] and geotransform[3] which define the positioning of the image top-left corner, but only found:

      arguments.append(unicode(geoTransform[1]))
      arguments.append(unicode(geoTransform[5]))

above lines are related to only pixel width and height.

I am in search of the GDAL code that has code snippets that involve positioning the raster and has functions to do the raster clipping operation.

Sai Krishna
  • 185
  • 1
  • 12

1 Answers1

5
  • If you installed QGIS using the OSGeo4W Network Installer:

    C:/OSGeo4W64/apps/qgis/python/plugins/processing/algs/gdal/ClipByMask.py
    

  • If you installed QGIS using the Standalone Installer (e.g. QGIS 2.18):

    C:/Program Files/QGIS 2.18/apps/qgis/python/plugins/processing/algs/gdal/ClipByMask.py
    
Joseph
  • 75,746
  • 7
  • 171
  • 282
  • 1
    Thank you. After reading the pyscript of "ClipByMask.py", I realize that it deals only with creating the argument which is in the format required to be given as input to some other GDAL algorithm. I couldn't trace the source GDAL algorithm that actually contains the code snippets to clip the raster. I am editing the question accordingly.. – Sai Krishna Dec 06 '16 at 12:12
  • @SaiKrishna - Apologies, hopefully others can advise on where that hidden code is =) – Joseph Dec 07 '16 at 09:26
  • Looking forward! – Sai Krishna Dec 07 '16 at 13:27
  • Unfortunately the problem is still present. To correct it, I use the script here => https://gis.stackexchange.com/questions/80774/translating-reposition-tiff-raster-layer-in-qgis given by maria – Xavier Michael Jun 21 '22 at 09:10
  • I have the same problem with this tool, but only when the Keep resolution of input raster option is selected. I've submitted a bug report at https://github.com/qgis/QGIS/issues/50801 – Stu Smith Nov 05 '22 at 18:31