Saturday 9 April 2016

Using GDAL library in QGIS plugin?


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?



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...