[GRASS-user] d.rast in python script

Laurent C. lrntct at gmail.com
Sat Oct 20 14:06:38 PDT 2018


Hello Frank,

It is not very straightforward, but it is possible.
Here is an example on how I do it:

import os
import grass.script as gscript
from grass.pygrass.gis.region import Region

# Set general env
os.environ['GRASS_RENDER_IMMEDIATE'] = "cairo"
os.environ['GRASS_RENDER_FILE_COMPRESSION'] = "9"
os.environ['GRASS_RENDER_FILE_READ'] = "TRUE"

# Set image size using the region
region = Region()
xr = region.cols
yr = region.rows
ratio = xr/yr
height = int(WIDTH / ratio)  # Choose the width you like
os.environ['GRASS_RENDER_WIDTH'] = str(WIDTH)
os.environ['GRASS_RENDER_HEIGHT'] = str(height)

# Then you can draw
os.environ['GRASS_RENDER_FILE'] = img_file_name
gscript.run_command('d.rast', map=my_map, quiet=True)


Be aware that every time you run your script, it will add layer on the file.
So you might want to delete the png file between the runs.

Cheers,
Laurent

Le ven. 19 oct. 2018 à 13:00, Frank David <frank.david at geophom.fr> a écrit :
>
> Hello,
>
> I wrote some python script and I do not find how to display created
> rasters.
>
> I tried to use d.rast but I believe this command is not designed to be
> used in python script (no monitor available with d.mon -l). Am I wright
> ? so how to do ?...
>
> Thank you for your help.
>
> Frank
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20181020/e43236fe/attachment.html>


More information about the grass-user mailing list