[Qgis-developer] Python plugin - Path to gdal

William Kyngesburye woklist at kyngchaos.com
Wed Nov 10 10:01:51 EST 2010


On Nov 10, 2010, at 8:38 AM, Barry Rowlingson wrote:

> On Wed, Nov 10, 2010 at 2:04 PM, kimaidou <kimaidou at gmail.com> wrote:
> 
>> I have no idea how I can find the path of the gdal binary used by Qgis. Of
>> course I need an OS independant method.
>> 
>> I tried to read the GdalTool plugin code, but woow, it is a bit too
>> complicated for me rigth now. E.g, I have seen there is a function :
>> 
>> # Retrieves GDAL binaries location
>> def getGdalPath():
>>   settings = QSettings()
>>   return settings.value( "/GdalTools/gdalPath", QVariant( "" ) ).toString()
>> 
>> But I am not sure it will work if run from another plugin (especially if
>> GdalTool is not installed/active ).
> 
> That's about right. GdalTools has a preferences dialog (in the
> Raster... GdalTools Settings option) that lets you specify a path to
> the gdal executables. I'm guessing that if the GdalTools guys couldnt
> find a better way, then you won't either :)
> 
> I would suggest you try getting the same setting from QSettings, and
> if that doesn't exist you'll need to get it from the user and store it
> yourself in a QSettings parameter for your plugin. Actually I think if
> the command is in your PATH then QProcess should find it without you
> having to specify it.
> 
I believe the gdaltools plugin path setting adds that setting to the PATH, so it can run the tools as you say without specifying the full path to any tool.

But, don't rely on the PATH from the environment if you want an OS independent method - OS X applications don't get variables from the shell environment, though they know how to use them.  Plugin developers still need to handle settings like this and add them to the QGIS environment.

I have a feature request for a QGIS-wide generic environment settings so that plugin developers don't have to reinvent various common settings like PATH.

http://trac.osgeo.org/qgis/ticket/3097

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

Theory of the Universe

There is a theory which states that if ever anyone discovers exactly what the universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarrely inexplicable.  There is another theory which states that this has already happened.

-Hitchhiker's Guide to the Galaxy 2nd season intro




More information about the Qgis-developer mailing list