Opened 10 years ago
Last modified 6 years ago
#2665 new defect
d.* modules not working from python or bash scripts (GRASS 7.0, Linux / Windows7)
Reported by: | santipardo | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 7.6.2 |
Component: | Display | Version: | 7.0.0 |
Keywords: | d.mon, d.vect, d.rast, python, script, bash | Cc: | |
CPU: | x86-64 | Platform: | All |
Description
(I copy here this question from GIS.stackexhange, related to a possible bug when calling d.* modules from a script)
Do d.* commands from GRASS GIS 7.0 run from a python script? I'm trying with this code:
import grass.script as grass grass.run_command('d.mon', start="wx3", resolution = '1') grass.run_command('d.mon', select="wx3") grass.run_command('d.rast', map="M01relief") grass.run_command('d.mon', select="wx3") grass.run_command('d.vect', map="M03PTEtramos", color="black", width='2')
When executing the complete script, the wx3 monitor starts, but remains empty. However, if I paste the commands one by one in GRASS Python Command-line, I get the layers drawn in the monitor. And using Cairo driver, I also get the layers drawn in a PNG file (directly from the script).
In the aforementioned Python code, the monitor seems not to apply the code, because if I check for the monitor commands, I get no info:
grass.run_command('d.mon', flags="c") [Empty output]
(The monitor wx3 opens and remains empty)
Using a Bash script, the monitor is again empty:
d.mon start=wx3 resolution=1 d.rast map=M01relief d.vect map=M03PTEtramos color=black width=2 d.redraw
But if I ask then for the list of commands I get results:
d.mon -c Enlistar comandos para el monitor <wx3>: d.rast map="M01relief" bgcolor="white" d.vect map="M03PTEtramos" layer="1" display="shape" type="point,line,boundary,area,face" color="black" fill_color="200:200:200" width=2 width_scale=1 icon="basic/x" size=5 label_layer="1" label_color="red" label_bgcolor="none" label_bcolor="none" label_size=8 xref="left" yref="center"
Actually, doing d.redraw from command line (not from the script), shows the map.
The problem happens both in Linux Mint 64 bits and Windows7 64 bits (the second running in a VirtualBox machine)
Change History (11)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
PROVISIONAL WORKAROUND: I have found that if I open a second monitor after the first, the layers are shown:
grass.run_command('d.mon', start="wx3", resolution = '2') grass.run_command('d.rast', map="M01relief", overwrite="true") grass.run_command('d.mon', start="wx0", resolution = '1') grass.run_command('d.rast', map="M01relief", overwrite="true") grass.run_command('d.mon', select="wx3") grass.run_command('d.redraw', verbose="true")
With this code, I get an empty "wx0" monitor, and a "wx3" monitor showing my layers. But I need that second 'ghost' monitor, which is not very elegant... Any help with this is welcome.
comment:3 by , 10 years ago
Priority: | normal → minor |
---|
comment:8 by , 9 years ago
Milestone: | 7.0.4 → 7.0.5 |
---|
comment:9 by , 8 years ago
Milestone: | 7.0.5 → 7.0.6 |
---|
comment:10 by , 7 years ago
Milestone: | 7.0.6 → 7.0.7 |
---|
comment:11 by , 6 years ago
Milestone: | 7.0.7 → 7.6.2 |
---|
This is weird. The commands are written to the cmd file of the monitor (e.g.: .tmp/24518.0.cmd):
But I do not get the layers shown until I manually open the file (in a text editor) and save it. Using some python code to open, edit and save the trick doesn't work:
Here I open the file in append mode, and add a line for 'd.redraw'. But it doesn't work, I have to open and save manually the file...