[GIS] Using GDAL library in QGIS plugin

gdalqgisqgis-plugins

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?

Best Answer

Yes.

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

Related Question