[GRASS-dev] [GRASS GIS] #2873: Simplify usage of GRASS in Python from outside
GRASS GIS
trac at osgeo.org
Sat Jan 23 19:50:09 PST 2016
#2873: Simplify usage of GRASS in Python from outside
-------------------------+-------------------------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
Type: | Status: new
enhancement |
Priority: major | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: startup, installation, scripts,
| interpreter, windows installer, pygrass,
CPU: | temporal, bootstrap, boilerplate
Unspecified | Platform: All
-------------------------+-------------------------------------------------
Comment (by wenzeslaus):
I uploaded a second prototype of the API as a patch. Before executing the
code outside of GRASS GIS, the following is needed:
{{{
#!bash
export GRASS_EXECUTABLE="/path/to/grass" # if GRASS is not on path
export LD_LIBRARY_PATH=$($GRASS_EXECUTABLE --config path)/lib
export PYTHONPATH=$($GRASS_EXECUTABLE --config path)/etc/python
}}}
The minimal script is:
{{{
#!python
import grass.script as gscript
import grass.script.setup as gsetup
session = gsetup.init_data("~/grassdata", "nc_spm", "user1")
# code goes here, e.g. gscript.run_command(...)
session.close()
}}}
The names and the overall API is not final, nor is the implementation and
it might be nicer to have one import instead two. However, I think the
basic structure is right. Please comment.
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2873#comment:4>
GRASS GIS <https://grass.osgeo.org>
More information about the grass-dev
mailing list