Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is it possible to reach the Spatial Query plugin functionality in QGIS from a Python script (PyQGIS)? If so, how do I accomplish this? Haven't found any documentation for it, even in the C++ API docs...

Regards, Andreas

share|improve this question
Apart from the suggestions from Sylvester, I'd like to understand if it's possible to reach other QGIS plugins from PyQGIS or just the native API? Is it really impossible to use the Spatial Query plugin from PyQGIS? How about the fTools plugins? I would e.g. like to reach "Random Points" in the Vector->Research Tools menu from script, isn't that possible? – Andreas Mar 14 '12 at 7:31

3 Answers

Yes, you can access plugin functions from a Python script e.g. to access fTools try in the QGIS Python console:

from fTools.fTools import fToolsPlugin

or more generic for other plugins:

from <plugin>.<file> import <class>
share|improve this answer

You can write your own function in Python easily enough using one of the many excellent Python APIs available. Have a look at GDAL/OGR. The documentation is focussed on C++ but you should be able to understand it enough to figure out the Pythonic equivalent. A great tutorial on this can be found here. Alternatively try 'Shapely'. If you are comfortable with databases have a look at PostGIS or SpatiaLite.

All of these have Python API that will allow you to construct your own queries for all the spatial queries that you can find in QGIS or ArcGIS or almost any GIS. To get started I recommend going through the tutorial for GDAL/OGR above and then branching out.

share|improve this answer
Ok, thanks for the links. Will look into this. – Andreas Mar 14 '12 at 7:28

It is not possible to get access to the spatial query plugin, because it is a C++ plugin without python bindings.

For python plugins in contrast, it is possible to import other plugin's interfaces by using the method outlined by webrian

from <plugin>.<file> import <class>

You can also get access to loaded and instantiated plugins by using

qgis.utils.plugins['pluginname']

In this case, the best shot is to write logic based on existing libraries as outlined by MappaGnosis.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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