Hello Joseph,
This is the way I work with grass from python:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
#1. Define function
def conectar(location,mapset):
# path to the GRASS GIS launch script
grass7bin = '/usr/bin/grass72'
# Set GISDBASE environment variable
gisdb = "/media/andres/Andres/TesisGrass"
os.environ['GISDBASE'] = gisdb
# query GRASS 7 itself for its GISBASE
gisbase = "/usr/lib/grass72"
os.environ['GISBASE'] = gisbase
# define GRASS-Python environment
gpydir = "/usr/lib/grass72/etc/python"
sys.path.append(gpydir)
# import GRASS Python bindings
import grass.script.setup as gsetup
############ launch session
gsetup.init(gisbase, gisdb, location, mapset)
#2. Now you can connect with your projects
location = "your location"
mapset = "your mapset"
conectar(location,mapset)
#3. Call function (examples)
gscript.run_command('g.region', n=float(n), s=float(s), e=float(e),
w=float(w), ewres=float(res), nsres=float(res))
gscript.run_command("r.in.gdal", input="/home/..../image.tif",
flags='e',output = "image")
2017-04-04 11:12 GMT-03:00 Joseph Kariuki <[email protected]>:
> Hi?
>
> I have been trying to call GRASS modules using python outside GRASS
> session, I am coding in PyCharm however, I am having a problem importing
> grass scripts and the solution being provided is setting GRASS environment
> variables. How do I go about that so to import GRASS modules in Pycharm?
>
>
> Kind Regards,
>
> *Joseph Kariuki*
>
> *Geospatial Engineer** | **GIS / Web Developer*
>
> _______________________________________________
> grass-user mailing list
> [email protected]
> https://lists.osgeo.org/mailman/listinfo/grass-user
>
_______________________________________________
grass-user mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/grass-user