I am trying to develop Grass GIS based app for hydrological analysis. Environment setting for GRASS GIS is working fine. Module import is working well. However, following line of code does not open display window.
2017-01-03 7:19 GMT+01:00 Ang Sherpa <angsherpa232@gmail.com>:
I am trying to develop Grass GIS based app for hydrological analysis.
Environment setting for GRASS GIS is working fine. Module import is working
well. However, following line of code does not open display window.
I tested simple script (attached) in running GRASS on GNU/Linux and it
worked. You just need to add time.sleep() after d.mon otherwise data
are not rendered properly. Martin
2017-01-03 12:13 GMT+01:00 Ang Sherpa <angsherpa232@gmail.com>:
[once more, please keep discussion on ML]
I tried still no luck. I am in windows 10. I tried whole day so almost out
of option. Your help will be grateful.
I tested script on Windows too, it worked, I just needed to increase
sleep to 2secs. This is hidden bug when using graphical monitors in
scripts. It should be solved. You should get at least some error. Eg.
unknown monitor size. Can you reproduce this issue with north carolina
dataset? If so, please sent us the sample.
1) does your script work from running GRASS (launch script from the GUI) [1]
2) does your script work with file-based display drivers (d.mon
start=cairo output=/path/to/image.png; d.vect ...; d.mon stop=cairo)
My script work from “Launch Script” command within Grass Gis environment. However, as a standalone script it just executes nothing not even error. So, sleep.time(2) is also not working as expected. Am I missing something?
I have attached the script that I used herewith this mail.
I tried still no luck. I am in windows 10. I tried whole day so almost out
of option. Your help will be grateful.
I tested script on Windows too, it worked, I just needed to increase
sleep to 2secs. This is hidden bug when using graphical monitors in
scripts. It should be solved. You should get at least some error. Eg.
unknown monitor size. Can you reproduce this issue with north carolina
dataset? If so, please sent us the sample.
does your script work from running GRASS (launch script from the GUI) [1]
does your script work with file-based display drivers (d.mon
start=cairo output=/path/to/image.png; d.vect …; d.mon stop=cairo)
2017-01-04 11:59 GMT+01:00 Ang Sherpa <angsherpa232@gmail.com>:
My script work from "Launch Script" command within Grass Gis environment.
However, as a standalone script it just executes nothing not even error. So,
sleep.time(2) is also not working as expected. Am I missing something?
I have attached the script that I used herewith this mail.
Will be looking forward to hearing from you.
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')
Thanks Martin for your response. Actually, cairo is good idea, however, what I am trying to do is building an app. I have already invested lots of my time developing interactive gui as shown in the attached screenshot. My ultimate plan with grass gis is mentioned in the red-box in attached screenshot.
I have a feeling that this process should work as expected.
Isn’t there any way to make grass gis run in background or some kind of temporary directory?
Is there any way that can run the GRASS GIS COMMAND SHELL without running the wxgui?
Interestingly in d.mon document it says that “The desired monitor should be started once and need not be restarted unless it is stopped for some reason. A monitor may continue to run for any length of time, even when no GRASS session is being run.” But don’t know what these exactly means if working through standalone script.
I will be really grateful if you could show me some way to make this work.
Will be looking forward to hearing from you.
My script work from “Launch Script” command within Grass Gis environment.
However, as a standalone script it just executes nothing not even error. So,
sleep.time(2) is also not working as expected. Am I missing something?
I have attached the script that I used herewith this mail.
Will be looking forward to hearing from you.
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:
file-based monitors (which is natural for script, generate
something, render to file and close)
if you are building a gui application then you should use a different
approach, and integrate the map window in your app and not use
monitors at all. Look for example at g.gui.rlisetup - in the wizard
select a raster map and 'Draw the sampling frame' and you will get a
new page with embedded map window. See https://trac.osgeo.org/grass/browser/grass/trunk/gui/wxpython/rlisetup/sampling_frame.py#L87
for implementation. This specific example might be more complicated
than what you need. It depends what kind of functionality you want, is
just display enough?
Anna
On Thu, Jan 5, 2017 at 1:43 AM, Ang Sherpa <angsherpa232@gmail.com> wrote:
Thanks Martin for your response. Actually, cairo is good idea, however, what
I am trying to do is building an app. I have already invested lots of my
time developing interactive gui as shown in the attached screenshot. My
ultimate plan with grass gis is mentioned in the red-box in attached
screenshot.
I have a feeling that this process should work as expected.
1. Isn't there any way to make grass gis run in background or some kind of
temporary directory?
2. Is there any way that can run the GRASS GIS COMMAND SHELL without running
the wxgui?
2. Interestingly in d.mon document it says that "The desired monitor should
be started once and need not be restarted unless it is stopped for some
reason. A monitor may continue to run for any length of time, even when no
GRASS session is being run." But don't know what these exactly means if
working through standalone script.
I will be really grateful if you could show me some way to make this work.
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 Wed, Jan 4, 2017 at 5:02 PM, Martin Landa <landa.martin@gmail.com> wrote:
Hi,
2017-01-04 11:59 GMT+01:00 Ang Sherpa <angsherpa232@gmail.com>:
> My script work from "Launch Script" command within Grass Gis
> environment.
> However, as a standalone script it just executes nothing not even error.
> So,
> sleep.time(2) is also not working as expected. Am I missing something?
> I have attached the script that I used herewith this mail.
>
> Will be looking forward to hearing from you.
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')
Note the comments starting #%. These are specifying the interface, both
command line and GUI. For example, if you specify that you want coordinates
as input, you will get a button to get coordinates by clicking in a Map
Display assuming that you are running the module in wxGUI (see r.profile
dialog).
You can execute any GRASS GIS module as subprocess in any application given that you setup the environment correctly or you are in GRASS session. One way how to achieve this is using grass72 --exec interface (see the doc). Modules which are interactive GUIs (d.mon wx0, g.gui, …) are more tricky because they are persistent and asynchronous; if usage is appropriate depends on the specific use case.
2017-01-08 11:06 GMT+01:00 Ang Sherpa <angsherpa232@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
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.
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:
file-based monitors (which is natural for script, generate
something, render to file and close)
On Mon, Jan 9, 2017 at 5:01 AM, Ang Sherpa <angsherpa232@gmail.com> wrote:
However, the d.mon does not open even after executing
from grass.script.setup import set_gui_path
set_gui_path()
This is not related to `d.mon wx1` (at least not directly). This is for
cases when you write your GUI using wxPython and GRASS' wxGUI. Kind of like
the following (which is actually d.mon wx* implementation) but simpler:
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)
This is missing --exec parameters and is likely not appropriate together
with grass.script.setup.init().
However, the question is, why do you need it and what would you do with
that if it worked? Do you want to just show the data? Or do you want to
interact with the display? Get coordinates? Set computational region? Why
not running in the GRASS GIS and let user use standard ways of setting
computational region extent and resolution? Gives using `g.gui -f` instead
of `d.mon wx1` an acceptable result? (I probably need detailed answer to
each of those questions to understand what you are trying to achieve.)