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.

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
    
  • 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 6 '16 at 12:12
  • @SaiKrishna - Apologies, hopefully others can advise on where that hidden code is =) – Joseph Dec 7 '16 at 9:26
  • Looking forward! – Sai Krishna Dec 7 '16 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.