[GRASS-user] batch job

Carmine Massarelli carmine.massarelli at ba.irsa.cnr.it
Fri Mar 17 04:21:13 PDT 2017


thanks

Il 03/16/2017 11:04 PM, Andres Solarte ha scritto:
> Hello Carmine, what I do is create a script (connect.py) to start 
> session as follows:
>
> # -*- coding: utf-8 -*-
> import os
> import sys
>
> def launch(location,mapset,db):
> # path to the GRASS GIS launch script
> grass7bin = '/usr/bin/grass72'
>
> # Set GISDBASE environment variable
> 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)
>
>
>
> After that I call the function from my main script and execute the 
> functions as follows
> #!/usr/bin/env python # -*- coding: UTF-8 -*- import connect #this is 
> the script to connect with grass
> gisdb = "/path/to/the/main/folder/"
> location = "/path/to/the/location/"
> mapset = "/path/to/the/mapset/"
> #Connect connect.launch(location,mapset,gisdb) import grass.script as 
> gscript
> #Now I can execute the functions using gscript.run_command as follows:
> #Load map
> gscript.run_command("r.in.gdal", input="input image", flags='e' 
> ,output = "map name")
> #Set region gscript.run_command('g.region', n=north, s=south, e=east, 
> w=west, ewres=resX, nsres=resY)
> I hope this helps
> Regards,
> Andrés.
>
> 2017-03-16 12:53 GMT-03:00 Carmine Massarelli 
> <carmine.massarelli a ba.irsa.cnr.it 
> <mailto:carmine.massarelli a ba.irsa.cnr.it>>:
>
>     Dear,
>     I have prepared a couple of scripts to execute a batch job: the
>     first opens a csv file and formats the data for the second
>     (invoked from the first) that include some grass functionality.
>     The second script uses grass functionality without starting grass
>     explicitly.
>     If I execute the first script from shell all it is working, but if
>     i invoke it from a php button (shell_exec('python
>     path/script.py')) I receive the error: /Cannot find GRASS GIS 7
>     start script (['grass72', '--config', 'path'])/
>     I saw that it is related to subprocess (here the code):
>
>     /p = subprocess.Popen(startcmd,
>     shell=False,stdout=subprocess.PIPE, stderr=subprocess.PIPE)//
>     //out, err = p.communicate()//
>     //if p.returncode != 0://
>     //    print >>sys.stderr, "ERROR: Cannot find GRASS GIS 7 start
>     script (%s)" % startcmd//
>     //    sys.exit(-1)//
>     //gisbase = out.strip('\n\r')/
>
>     but I am not expert about this, so I ask for your help.
>     What could I do?
>     I have already set sudoers   www-data ALL=NOPASSWD: ALL   and
>     checked permission.
>     Thanks in advance
>
>     carmine
>
>
>     _______________________________________________
>     grass-user mailing list
>     grass-user a lists.osgeo.org <mailto:grass-user a lists.osgeo.org>
>     https://lists.osgeo.org/mailman/listinfo/grass-user
>     <https://lists.osgeo.org/mailman/listinfo/grass-user>
>
>

Dr. Nat. Carmine Massarelli, Ph.D.
Environmental Technologist

IRSA-CNR
Mob: +39 339 32 57 311
Tel: +39 080 582 05 06
Addr: Via De Blasio, n.5 - 70132 (Ba) - IT

-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20170317/b6ad47de/attachment-0001.html>


More information about the grass-user mailing list