[GRASS-dev] grass-dev Digest, Vol 82, Issue 57

Brian Sanjeewa Rupasinghe jinkabs at gmail.com
Mon Dec 31 23:48:38 PST 2012


Hi Thanks,

My requirement is to run GRASS commands outside GRASS with Python 2.7.3
installed in Windows 7 machine with
OGR Python bindings. According to sources, there are two possible ways to
connect to GRASS data through external Python.
The first method is described in
http://grasswiki.osgeo.org/wiki/GRASS_and_Python. However when i set the
environment variables in my machine according to above wiki, I cannot
connect to GRASS 6.4.3 with Python 2.7.3. When i use following
two imports:
>> import os, sys
>>
>> From grass.lib import grass
>>

For the second one, it gives an error message saying "No module named
grass.lib"

Then using the second method, i tried to connect to GRASS with GDAL/OGR
grass support. For this i needed to have gdal_grass plugin installed with
GRASS. So i compiled GRASS and gdal_grass with OSGEO4W. The stable release
of
GRASS 6 in OSGEO4W uses gdal 1.9 and the gdal_grass plugin for latest
version is not available in OSGEO4W. The only available plugins are for
gdal 1.5 and 1.6 versions under OBSOLETE category of OSGEO4W. I installed
both of these and checked GDAL/OGR GRASS support is available within GRASS
by typing at GRASS command shell the following:

ogrinfo --formats
gdalinfo --formats

But i cannot find gdal_grass support over there. Had it been there i could
have read GRASS data as explained by the following code provided my Python
has OGR python bindings:

from osgeo import ogr
ds = ogr.Open('D:/UEL/GrassGISDB/SLD99/LBS/vector/CluterCleaned/head')
layer = ds.GetLayer(0)

However when i execute above this is the error i get because of the
non-availability of gdal_grass plug-in


Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    layer = ds.GetLayer(0)
AttributeError: 'NoneType' object has no attribute 'GetLayer'


The PyGRASS module you have mentioned is a good candidate for working
with/ accessing GRASS. However, to

me i need to access GRASS with external Python and not in the Python
shell given in GRASS itself. Is it possible

to install PyGRASS module for Python 2.7 in windows like installing
numpy or matplotlib modules separate? I hope

you understand my question better.

Cheers, Brian.


On Tue, Jan 1, 2013 at 8:53 AM, Rashad M <mohammedrashadkm at gmail.com> wrote:

> Did you tried new grass python API?. Before that could you tell what error
> you are getting?
>
> [0] http://code.google.com/p/pygrass/
> [1] http://www.ing.unitn.it/~zambelli/projects/pygrass/
>
>
> On Mon, Dec 31, 2012 at 7:14 PM, Brian Sanjeewa Rupasinghe <
> jinkabs at gmail.com> wrote:
>
>> Hi,
>>
>> Actually my requirement is to run Python script outside GRASS Python
>> shell. For this i tried connecting to GRASS outside with Python following
>> the GRASS-wiki instructions, but failed. Then i tried to connect to GRASS
>> with OGR Python bindings, it too failed because gdal_grass plugin provided
>> in OSGEO4W does not install in GRASS (they are considered obsolete in
>> OSGEO4W). However i installed gdal1.6_grass with stable release of GRASS
>> 6.4.3 (run with gdal latest version 1.9.x) in OSGEO4W. However, when
>> checked for the installed packages, gdal_grass support is not provided. It
>> is highly appreciated if it is included in the current OSGEO4W setup or any
>> suggestion.
>>
>> Cheers, Brian
>>
>> On Sun, Dec 30, 2012 at 1:30 AM, <grass-dev-request at lists.osgeo.org>wrote:
>>
>>> Send grass-dev mailing list submissions to
>>>         grass-dev at lists.osgeo.org
>>>
>>> To subscribe or unsubscribe via the World Wide Web, visit
>>>         http://lists.osgeo.org/mailman/listinfo/grass-dev
>>> or, via email, send a message with subject or body 'help' to
>>>         grass-dev-request at lists.osgeo.org
>>>
>>> You can reach the person managing the list at
>>>         grass-dev-owner at lists.osgeo.org
>>>
>>> When replying, please edit your Subject line so it is more specific
>>> than "Re: Contents of grass-dev digest..."
>>>
>>> Today's Topics:
>>>
>>>    1. Re: GRASS Vector Support (J?rgen E. Fischer)
>>>    2. Re: Grass7 GUI compilation failed (Rashad M)
>>>
>>>
>>> ---------- Forwarded message ----------
>>> From: "Jürgen E." Fischer <jef at norbit.de>
>>> To: grass-dev at lists.osgeo.org
>>> Cc:
>>> Date: Sat, 29 Dec 2012 17:42:00 +0100
>>> Subject: Re: [GRASS-dev] GRASS Vector Support
>>> Hi Brian,
>>>
>>> On Sat, 29. Dec 2012 at 10:58:19 +0530, Brian Sanjeewa Rupasinghe wrote:
>>> > I need to automate some GRASS functions in my research work. If there
>>> is a
>>> > possibility to build gdal_grass plugin for Windows it is highly
>>> > appreciated. Even the Python scripts that call GRASS functions from
>>> > outside for MS_Windows do not connect with GRASS even though the
>>> > instructions provided in the GRASS wiki is followed. I have posted this
>>> > problem in grass-windows forum and finally advised me to bring the
>>> problem
>>> > down to grass-dev list.
>>>
>>> And you are positive that the GDAL plugin would help?  The above
>>> description
>>> sounds like a more general problem and I don't see any connection to the
>>> missing plugin at all.
>>>
>>> Does GRASS itself need the GDAL GRASS plugin at all?
>>>
>>>
>>> Jürgen
>>>
>>> --
>>> Jürgen E. Fischer         norBIT GmbH               Tel.
>>> +49-4931-918175-31
>>> Dipl.-Inf. (FH)           Rheinstraße 13            Fax.
>>> +49-4931-918175-50
>>> Software Engineer         D-26506 Norden
>>> http://www.norbit.de
>>> committ(ed|ing) to Quantum GIS                         IRC: jef on
>>> FreeNode
>>>
>>> --
>>> norBIT Gesellschaft fuer Unternehmensberatung und Informationssysteme mbH
>>> Rheinstrasse 13, 26506 Norden
>>> GF: Jelto Buurman, HR: Amtsgericht Emden, HRB 5502
>>>
>>>
>>>
>>>
>>> ---------- Forwarded message ----------
>>> From: Rashad M <mohammedrashadkm at gmail.com>
>>> To: grass-dev at lists.osgeo.org
>>> Cc:
>>> Date: Sat, 29 Dec 2012 23:55:17 +0530
>>> Subject: Re: [GRASS-dev] Grass7 GUI compilation failed
>>> here is output from v.digit
>>> make
>>> ml
>>> make[6]: Entering directory `/code/grass/grass70/gui/wxpython/vdigit'
>>> GISRC=/code/grass/grass70/dist.x86_64-unknown-linux-gnu/demolocation/.grassrc70
>>> GISBASE=/code/grass/grass70/dist.x86_64-unknown-linux-gnu
>>> PATH="/code/grass/grass70/dist.x86_64-unknown-linux-gnu/bin:/code/grass/grass70/dist.x86_64-unknown-linux-gnu/bin:$PATH"
>>> PYTHONPATH="/code/grass/grass70/dist.x86_64-unknown-linux-gnu/etc/python:/code/grass/grass70/dist.x86_64-unknown-linux-gnu/etc/python:$PYTHONPATH"
>>> LD_LIBRARY_PATH="/code/grass/grass70/dist.x86_64-unknown-linux-gnu/bin:/code/grass/grass70/dist.x86_64-unknown-linux-gnu/lib:/code/grass/grass70/dist.x86_64-unknown-linux-gnu/lib:"
>>> LC_ALL=C
>>> /code/grass/grass70/dist.x86_64-unknown-linux-gnu/scripts/g.gui.vdigit
>>> --html-description < /dev/null | grep -v '</body>\|</html>' >
>>> g.gui.vdigit.tmp.html
>>> Traceback (most recent call last):
>>>   File
>>> "/code/grass/grass70/dist.x86_64-unknown-linux-gnu/scripts/g.gui.vdigit",
>>> line 39, in <module>
>>>     import wx
>>> ImportError: No module named wx
>>> make[6]: *** [g.gui.vdigit.tmp.html] Error 1
>>> rm g.gui.vdigit.tmp.html
>>> make[6]: Leaving directory `/code/grass/grass70/gui/wxpython/vdigit'
>>> make[5]: *** [guiscript] Error 2
>>>
>>>
>>> On Sat, Dec 29, 2012 at 9:57 PM, Rashad M <mohammedrashadkm at gmail.com>wrote:
>>>
>>>> grass7.0 fails compilation at first and continues only after setting
>>>> PYTHONPATH.
>>>>
>>>> This becomes a routine for recompilation. Is there any work around to
>>>> automatically pickup wxPython?
>>>>
>>>> Here is my error log:
>>>>
>>>> Started compilation: Sat Dec 29 21:46:17 IST 2012
>>>> --
>>>> Errors in:
>>>> /code/grass/grass70/gui/wxpython/animation
>>>> /code/grass/grass70/gui/wxpython/mapswipe
>>>> /code/grass/grass70/gui/wxpython/gmodeler
>>>> /code/grass/grass70/gui/wxpython/rlisetup
>>>> /code/grass/grass70/gui/wxpython/psmap
>>>> /code/grass/grass70/gui/wxpython/dbmgr
>>>> /code/grass/grass70/gui/wxpython/vdigit
>>>> --
>>>> In case of errors please change into the directory with error and run
>>>> 'make'.
>>>> If you get multiple errors, you need to deal with them in the order they
>>>> appear in the error log. If you get an error building a library, you
>>>> will
>>>> also get errors from anything which uses the library.
>>>> --
>>>> Finished compilation: Sat Dec 29 21:53:10 IST 2012
>>>>
>>>>
>>>> wxpython is installed from ubuntu repos. so its in the default path
>>>>
>>>>
>>>> --
>>>> Regards,
>>>>    Rashad
>>>>
>>>
>>>
>>>
>>> --
>>> Regards,
>>>    Rashad
>>>
>>> _______________________________________________
>>> grass-dev mailing list
>>> grass-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/grass-dev
>>>
>>
>>
>> _______________________________________________
>> grass-dev mailing list
>> grass-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/grass-dev
>>
>
>
>
> --
> Regards,
>    Rashad
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20130101/65e72fb8/attachment-0001.html>


More information about the grass-dev mailing list