[Qgis-developer] Calling GRASS From a Python QGIS Script
G. Allegri
giohappy at gmail.com
Tue Jun 28 02:36:43 EDT 2011
The problem is probably related to the way the Subprocess module handles the
I/O inside the QGis python console. It's a problem I've read about various
times, and is specific of the Windows environemnt.
Two thread I recently read about this are [1] and [2], and both consider it
a Subprocess bug.
I hope to find some time to reproduce it...
giovanni
[1] http://bugs.python.org/issue3905
[2]
http://bytes.com/topic/python/answers/634409-subprocess-handle-invalid-error
2011/6/28 romain riviere <romain.riviere.974 at gmail.com>
> Hi all,
>
> I'm using windows XP and QGIS 1.7 (classic installation, python 2.5, grass
> 6.4.1 ). My Goal is to create a QGIS plugin for complex network analysis
> (TSP,steinman tree,...), using GRASS capabilities. It aims to be very
> user-friendly, and cross-platform.
> I'm trying to call GRASS from within a QGIS python plugin, but I get the
> following error (python console module):
>
> Code: (inspired by:
> http://grass.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly
> )
>
>> import os
>>> import sys
>>>
>>> gisbase = os.environ['GISBASE'] = r" ....path to QGIS ....
>>> sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python"))"
>>>
>>
>>
>>> import grass.script as grass
>>>
>>
> Error:
>
>> >>> import grass.script as grass
>>
>> Traceback (most recent call last):
>>
>> File "<input>", line 1, in <module>
>>
>> File "C:/PROGRA~1/QUANTU~2/apps/qgis/./python\qgis\utils.py", line 283, in
>> _import
>>
>> mod = _builtin_import(name, globals, locals, fromlist, level)
>>
>> File "C:\Program Files\Quantum GIS
>> Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\__init__.py", line 1,
>> in <module>
>>
>> from core import *
>>
>> File "C:/PROGRA~1/QUANTU~2/apps/qgis/./python\qgis\utils.py", line 283, in
>> _import
>>
>> mod = _builtin_import(name, globals, locals, fromlist, level)
>>
>> File "C:\Program Files\Quantum GIS
>> Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 1073,
>> in <module>
>>
>> debug_level = int(gisenv().get('DEBUG', 0))
>>
>> File "C:\Program Files\Quantum GIS
>> Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 514,
>> in gisenv
>>
>> s = read_command("g.gisenv", flags='n')
>>
>> File "C:\Program Files\Quantum GIS
>> Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 225,
>> in read_command
>>
>> ps = pipe_command(*args, **kwargs)
>>
>> File "C:\Program Files\Quantum GIS
>> Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 202,
>> in pipe_command
>>
>> return start_command(*args, **kwargs)
>>
>> File "C:\Program Files\Quantum GIS
>> Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 164,
>> in start_command
>>
>> return Popen(args, **popts)
>>
>> File "C:\Program Files\Quantum GIS
>> Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 55, in
>> __init__
>>
>> startupinfo, creationflags)
>>
>> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 587, in
>> __init__
>>
>> errread, errwrite) = self._get_handles(stdin, stdout, stderr)
>>
>> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 700, in
>> _get_handles
>>
>> p2cread = self._make_inheritable(p2cread)
>>
>> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 745, in
>> _make_inheritable
>>
>> DUPLICATE_SAME_ACCESS)
>>
>> WindowsError: [Error 6] The handle is invalid
>>
>
>
> I am pretty sure this is due to the Python Path, because the same code
> works well in a classic python console (outside QGIS). But I'm not able to
> resolve this issue. I haven't test yet, but I'm pretty sure it's working on
> ubuntu.
>
> Another Question:
>
> Does anyone know how to import QGIS vector layer directly into GRASS ( as
> v.in.ogr.qgis.loc from the GRASS Plugin)
>
>
> Any help is welcome.
>
> Romain,
> *
> *
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20110628/eabf33d1/attachment-0001.html
More information about the Qgis-developer
mailing list