Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I was wondering if it's possible to use Python and QGIS out of QGIS environment (namely, avoiding the use of the console). I'm pretty new to QGIS, I've been always using ArcGIS 10.1. What I am looking for is a thing similar to that "arcpy" module, since I work with tons of data at a time. Moreover, I'd like to use a good IDE, any suggestion? I'm using qgis 1.8, python 2.7.2 32bit, windows 7 64bit. P.S.: I couldn't really come up with a solution, neither following the instructions found in http://www.qgis.org/pyqgis-cookbook/intro.html#python-applications. Hope someone will enlight me!

share|improve this question
    
What error did you get when following the cookbook? –  Nathan W Jan 8 '13 at 22:03
add comment

2 Answers

up vote 4 down vote accepted

Under the hood QGIS uses GDAL/OGR for most of the functions. So, the Python API for GDAL would be the closest analogy to using ArcPY in a stand-alone situation.

You can use the installation that comes with QGIS or have a separate installation of Python and GDAL. Other addons that complete the 'package' I would include

The last two are particularly relevant for raster processing. Have a look here for a tutorial on stand-alone geoprocessing using GDAL. This will get you going.

share|improve this answer
    
Thank you so much, this is really helpful, think I'm going through all the documentations t learn more about how everything works! It's a bit old though, but it's superfine! –  user9518 Jan 9 '13 at 9:45
add comment

Yes building a standalone application out of QGIS using Python and the QGIS libraries is possible.

I have some small, but hopefully growing, example set at https://github.com/NathanW2/pyqgis-playground

The main thing is having the path the libraries setup correctly. When I'm on windows I use something like this:

@ECHO OFF
set PYTHONPATH=C:\OSGeo4W\apps\qgis-dev\python
Set PATH=C:\OSGeo4W\apps\qgis-dev\bin;%PATH%
set QGISHOME=C:\OSGeo4W\apps\qgis-dev\

python yourfile.py

and I run it from within inside the OSGeo4W shell. You can test you have everything setup correctly by running the above set commands inside a OSGeo4W shell and then doing:

C:\python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>>>> import qgis.core
>>>>>>

If it works you should get no errors.

share|improve this answer
    
I've been trying hard to set the system environment to point to the correct folders like you suggest, but still having troubles. When I try to import the "qgis.core" module, the SHELL tells me a DLL (which I suppose to be "qgis_core.dll") couldn't be load. I'm using a SHELL found in the installation of Python27. Guess if the ArcGIS references in the system environment might conflict with the QGIS ones... –  user9518 Jan 9 '13 at 9:55
    
Try using the Python that comes with OSGeo4W it has everything setup –  Nathan W Jan 9 '13 at 10:05
    
Ehy Nathan I came up with your page googling in the web (woostuff.wordpress.com/2011/09/27/…), really interesting! –  user9518 Jan 9 '13 at 10:21
    
Howerver, could you please tell me what is the SHELL that comes with the installation of QGIS. I didn't use the OSGeo4W setup, but one that I found in the QGIS official website, so it might have installed different files than those you could have. I'd really like to solve the problem of the system environment setting, maybe if you want, you could have a look –  user9518 Jan 9 '13 at 10:24
    
at my other question... gis.stackexchange.com/questions/45473/… –  user9518 Jan 9 '13 at 10:25
show 2 more comments

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.