[GRASS-user] [d.*] command not executing from standalone script

Ang Sherpa angsherpa232 at gmail.com
Mon Jan 9 02:01:05 PST 2017


This initiates the grass gis and will be running background.
subprocess.Popen(['cmd','/K','grass72 -text'],cwd=gisbase)

However, the d.mon does not open even after executing
from grass.script.setup import set_gui_path
set_gui_path()

Am I still missing something?

I also tried running by directly injecting 'd.mon start=wx1' command to the
subprocess itself. With this approach I got an error as stated in ##ERROR
(as shown in attachement_2)
subprocess.Popen(['cmd','/K','grass72 -text','*d.mon start=wx1*
'],cwd=gisbase)

##ERROR: Cleaning up temporary files...
Starting GRASS GIS...
ERROR: <C:\Users\WRPPF-A> is not a valid GRASS Location because PERMANENT
Mapset is missing
Exiting...
Press any key to continue . . .

I have attached the my script herewith this mail.
Will be looking forward to hearing from you.

*Regards,*
*Ang Dawa Sherpa*
*GIS technician - Irrigation Master Plan*
*WRPPF - DOI, Nepal Government*
*Lalitpur*
*contact: 984 007 3861*

On Sun, Jan 8, 2017 at 6:13 PM, Martin Landa <landa.martin at gmail.com> wrote:

> Hi,
>
> 2017-01-08 11:06 GMT+01:00 Ang Sherpa <angsherpa232 at gmail.com>:
> > However, still no changes, the [d.*] doesnot starts. Am I missing
> something?
> > I have attached the script herewith this mail.
>
>
> see my last replay:
>
> """
> interactive monitors require running GRASS. It is probably reason why
> wx monitor is not even launched since your script already terminates
> (and GRASS session too). It has no reason to use interactive monitors
> outside of GRASS. If you modify your script like:
>
> gscript.run_command('d.mon', stop='wx6') # we asssume that there is
> already monitors hanging from last run
> gscript.run_command('d.mon',start='wx6',resolution='1')
> time.sleep(2)
> gscript.run_command('d.rast',map='elevation')
> time.sleep(200)
> os.remove(rcfile)
>
> Then monitor shows and will running 200sec. But it has no sense. So I
> suggest you to use:
>
> 1) file-based monitors (which is natural for script, generate
> something, render to file and close)
>
> script.run_command('d.mon',start='cairo',resolution='1',
> output="/path/image.png")
> # no need to sleep
> gscript.run_command('d.rast',map='elevation')
> gscript.run_command('d.mon', stop='cairo')
>
> or
>
> 2) launch your script from running GRASS
> """
>
> Result: when using interactive monitors you need to have active GRASS
> session running on background. Ma
>
> --
> Martin Landa
> http://geo.fsv.cvut.cz/gwiki/Landa
> http://gismentors.cz/mentors/landa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20170109/736df856/attachment-0001.html>
-------------- next part --------------
#!/usr/bin/env python
import os
import sys
import time
import subprocess

gisdbase = os.path.join(os.path.expanduser("~"), "Documents\\grassdata")
location = "nc_spm_08_grass7"
mapset   = "user1"
gisbase  = os.environ['GISBASE'] = r'C:\Program Files\GRASS GIS 7.2.0'
sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python"))

import grass.script.setup as gsetup
import grass.script as gscript
from grass.script.setup import set_gui_path


#GRASS GIS will be running in the background
subprocess.Popen(['cmd','/K','grass72 -text'],cwd=gisbase)

#This throws PERMANENT mapset missing error
#subprocess.Popen(['cmd','/K','grass72 -text','d.mon start=wx1'],cwd=gisbase)

time.sleep(2)

rcfile = gsetup.init(gisbase,gisdbase, location, mapset)

print "grass environment"
gscript.message('Current Grass GIS 7 enviornment:')
print gscript.gisenv()
##print '\n'
##print gtask.command_info('r.info')
print gscript.read_command('r.info',map = 'accum_5k')
##time.sleep(2)


set_gui_path()

gscript.run_command('d.mon',start = 'wx4',resolution='1')
time.sleep(2)
gscript.run_command('d.rast',map = 'accum_5k')



os.remove(rcfile)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: perm_missing.JPG
Type: image/jpeg
Size: 31527 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20170109/736df856/attachment-0001.jpe>


More information about the grass-user mailing list