i've been working on my project to create QGIS plugin for raster analysis purpose.

It will be easier if we use gdal library.

Are we able to use gdal library to develop QGIS plugin?

If so, how do we set up the gdal package inside the qgis2 plugin environment?

1 Answer 1



Assuming you're using Python for your plugin, this should cover most things for raster-based processing.

from osgeo import osr
import gdal
from gdalconst import *

If your plugin needs to handle vector data, add in

from osgeo import ogr

If you've done a 'normal' install you should at least have GDAL, and so should your plugin users. This might not be the case for people using older versions of QGIS.

QGIS uses GDAL itself.

An example is the GDAL Tools Plugin. This is a python wrapper around the GDAL functionality (such as Contours, Sieve, Near-Black and so on). It also has the ui files that define the dialog boxes for changing the settings. A lot of the Raster menu is implemented this way.

I think this was originally a stand-alone plugin (in earlier versions) but was brought into core QGIS.

You can see the code in Github . I'm not sure if it uses GDAL directly, or indirectly (as a wrapper the command line)

This file shows an example of how to test for the libraries

  • 3
    It is advised to use from osgeo import gdal, since import gdal might not be supported for long
    – Kersten
    Commented Jul 19, 2015 at 19:27
  • Your Github links are 404.
    – user2856
    Commented Oct 1, 2017 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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