<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<div dir="auto">
<div dir="auto">Would this addon be useful? <a href="https://grass.osgeo.org/grass78/manuals/addons/m.printws.html">https://grass.osgeo.org/grass78/manuals/addons/m.printws.html</a></div><div dir='auto'><br></div>
<div id="aqm-original" style="color: black;">
<!-- body start -->
<div class="aqm-original-body"><div style="color: black;">
<p style="color: black; font-size: 10pt; font-family: sans-serif; margin: 8pt 0;">On February 11, 2021 6:55:24 PM Chris Bartolomei via grass-user <grass-user@lists.osgeo.org> wrote:</p>
<blockquote type="cite" class="gmail_quote" style="margin: 0 0 0 0.75ex; border-left: 1px solid #808080; padding-left: 0.75ex;">
<div class="ydpf4080730yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
<div dir="ltr" data-setdir="false">Good morning Anna,</div><div dir="ltr" data-setdir="false">It took quite a while of trial and error but I worked out a method that kindof works:</div><div dir="ltr" data-setdir="false">First off - unless someone says otherwise, you can't use the PNG driver (d.mon) method to overlay more than one polygon vector. Sorry - it just doesn't work. You CAN use the ps.map method - that works really well generating the image however it by default assumes you are printing on an A4 piece of paper so there's all sorts of white space. The image is centered at the top of this fictional piece of paper. In your postscript rules file you can use the "maploc" command to position the image elsewhere on the page. This is necessary because the next trick changes the paper dimensions but it assumes the origin is the lower left corner and therefore clips anything that is above the new dimensions. Back to postscript commands in the rules file first though ... the ps.map maploc command uses inches (why?? it should be <span>points</span>) so an A4 page is 8.27" x 11.69" <span>points</span> are 1/72 of an inch thus 595p x 842p - it also has a default 36p margin (0.5 inch). You'll need those numbers later. maploc also lets you set the size of your image box: maploc {x offset from left edge} {y offset from top} {width of box} {height of box} Note: this is all done via a BASH script with GRASS 7.4 on Linux (RHEL 7), not python. This is my postscript rules file:</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">maploc 0.1 6.815 6.5 4.875 #468p x 351p map box moved down towards the bottom of the page</div><div dir="ltr" data-setdir="false"># note that if you push it too far down to where the box would run off the bottom, the image is</div><div dir="ltr" data-setdir="false"># resized to fit on the page so do some testing to come up with the correct values</div><div dir="ltr" data-setdir="false"># also I found the computational region controls the aspect ratio so although I say <br></div><div dir="ltr" data-setdir="false"># 6.5 x 4.875 with the above maploc command, I got a 6.5 x 3.8 inch box.</div><div dir="ltr" data-setdir="false">border y # add a border to the map frame (box)</div><div dir="ltr" data-setdir="false"> color 81:81:81 # shade of gray</div><div dir="ltr" data-setdir="false"> end # end the border controls</div><div dir="ltr" data-setdir="false">vareas admin_area # top vector layer to display</div><div dir="ltr" data-setdir="false"> layer 1 # attribute table to use</div><div dir="ltr" data-setdir="false"> rgbcolumn area_color # name of column holding R:G:B values to fill the polygons</div><div dir="ltr" data-setdir="false"> color 153:153:153 #boundary color</div><div dir="ltr" data-setdir="false"> end # end the admin_area controls</div><div dir="ltr" data-setdir="false">vareas Country # this is the bottom vectors to display</div><div dir="ltr" data-setdir="false"> color 210:210:210 #boundary color</div><div dir="ltr" data-setdir="false"> fcolor 153:153:153 #fill color for all polygons</div><div dir="ltr" data-setdir="false"> end <span># end the Country controls</span></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span>Here's the command to run to generate the postscript file:</span></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span>ps.map input=$HOME/ps_rules.txt out=$HOME/color_admin.ps --overwrite</span></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span>To convert the postscript to PNG I had to use ghostscript - there are other tools you can use though.</span></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span></span>gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dDEVICEWIDTHPOINTS=473 -dDEVICEHEIGHTPOINTS=276 -dFIXEDMEDIA -dPSFitPage -sOutputFile=$HOME/color_admin.png -c "<</PageOffset [-34 78]>> setpagedevice" -f $HOME/color_admin.ps</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">So the above line needs some explaining (http://www.ghostscript.com/doc/9.27/Use.htm) but in a nutshell, the parameters to play with are first the Pageoffset [x y] values. They are in <span>points</span> not inches ... 1/72 inch = 1 point ... remember the 1/2" margins? the -34 gives me 2 <span><span>points</span></span> of white space to the left edge of the map frame, the 78 I had to play with to push the map frame down to the right spot.</div><div dir="ltr" data-setdir="false">Next is the DEVICEWIDTHPOINTS and DEVICEHEIGHTPOINTS ... again in points ... this "trims" the paper to height and width ... set something then run it and view the results. Adjust and run again until you get it correct.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">It's a royal pain but it seems to work this way. It would sure be nice to create a GRASS workspace file and just say "convert this workspace to an image" with everything all laid out nicely - like Arc does exporting their mxd map files...</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">I hope this helps someone !</div><div dir="ltr" data-setdir="false">:)<br><div>Chris</div></div><div dir="ltr" data-setdir="false"><br></div><div><br></div>
</div><div id="ydpa9ae8044yahoo_quoted_3940278452" class="ydpa9ae8044yahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
<div>
On Wednesday, February 10, 2021, 11:08:00 PM EST, Anna Petrášová <kratochanna@gmail.com> wrote:
</div>
<div><br></div>
<div><br></div>
<div><div id="ydpa9ae8044yiv7486881403"><div><div dir="ltr"><div dir="ltr"><br clear="none"></div><br clear="none"><div class="ydpa9ae8044yiv7486881403gmail_quote"><div class="ydpa9ae8044yiv7486881403gmail_attr" dir="ltr">On Tue, Feb 9, 2021 at 4:41 PM Chris Bartolomei <<a shape="rect" href="mailto:surfcjb@yahoo.com" rel="nofollow" target="_blank">surfcjb@yahoo.com</a>> wrote:<br clear="none"></div><blockquote class="ydpa9ae8044yiv7486881403gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><div><div style="font-family:Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
<div dir="ltr">Hi Anna - thank you for the suggestion - I tried it but alas, still it only outputs a single vector map (layer). I can get either the Country vector or the admin_areas vector, but not both overlaid.</div><div dir="ltr">:(</div><div dir="ltr">Chris<br clear="none"></div></div></div></blockquote><div><br clear="none"></div><div>I realized you are using both environmental variables and d.mon, that might cause some issues, you use one or the other. So try to remove the lines starting with d.mon.</div><div><br clear="none"></div><div>Hope that helps,</div><div class="ydpa9ae8044yiv7486881403yqt5532069994" id="ydpa9ae8044yiv7486881403yqtfd83027"><div>Anna </div><blockquote class="ydpa9ae8044yiv7486881403gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><div><div style="font-family:Helvetica, Arial, sans-serif;font-size:16px;"><div dir="ltr"></div><div><br clear="none"></div>
</div><div id="ydpa9ae8044yiv7486881403gmail-m_2928144459414188663ydpe852ea3cyahoo_quoted_3128130742">
<div style="font-family:Helvetica, Arial, sans-serif;font-size:13px;color:rgb(38,40,42);">
<div>
On Tuesday, February 9, 2021, 1:20:52 PM EST, Anna Petrášová <<a shape="rect" href="mailto:kratochanna@gmail.com" rel="nofollow" target="_blank">kratochanna@gmail.com</a>> wrote:
</div>
<div><br clear="none"></div>
<div><br clear="none"></div>
<div><div id="ydpa9ae8044yiv7486881403gmail-m_2928144459414188663ydpe852ea3cyiv8557192743"><div><div dir="ltr"><div dir="ltr">Hi,</div><br clear="none"><div><div dir="ltr">On Tue, Feb 9, 2021 at 10:25 AM Chris Bartolomei via grass-user <<a shape="rect" href="mailto:grass-user@lists.osgeo.org" rel="nofollow" target="_blank">grass-user@lists.osgeo.org</a>> wrote:<br clear="none"></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><div><div style="font-family:Helvetica, Arial, sans-serif;font-size:16px;"><div dir="ltr">Good morning :)</div><div dir="ltr">I'm using GRASS 7.4.1 on a Linux cluster so I only have command-line capability. I have two vector layers (a country boundary polygon and part of an administrative area map - also polygons). I am trying to automate creating a PNG file of the admin areas overlaying the country boundary therefore all work has to be command-line (in a bash script). I've tried this two ways - using the d.mon start=png method and also the ps.map method as described below. The d.mon method appears to generate the image with only one vector map (not both) and only colors the borders - it won't use the fill_color setting. The ps.map method seems to work but assumes the image is on a sheet of paper so there's a ton of extra white-space. I'd like to use d.mon but I can use ps.map if someone could please let me know how to export only the computational region without all the extra 'paper' in the image. Here's my code:</div><div dir="ltr"><br clear="none"></div><div dir="ltr">g.region vector='Country'</div><div dir="ltr">export GRASS_RENDER_IMMEDIATE=png</div><div dir="ltr"><span>export GRASS_RENDER_WIDTH=640</span></div><div dir="ltr"><span><span>export GRASS_RENDER_HEIGHT=480</span></span></div><div dir="ltr"><span><span><span>export GRASS_RENDER_TRANSPARENT=true</span></span></span></div><div dir="ltr"><span><span><span><span>export GRASS_RENDER_TRUECOLOR=true</span></span></span></span></div><div dir="ltr"><span><span><span><span><span>export GRASS_RENDER_FILE=$HOME/country_admin.png</span></span></span></span></span></div><div dir="ltr"><span><span><span><span><span><span>export GRASS_RENDER_FILE_COMPRESSION=0</span></span></span></span></span></span></div><div dir="ltr"><span><span><span><span><span><span><span>export GRASS_MESSAGE_FORMAT=plain</span></span></span></span></span></span></span></div><div dir="ltr">d.mon start=png</div><div dir="ltr">d.vect map=Country color=210:210:210 fill_color=153:153:153 display=shape type=area</div><div dir="ltr">d<span>.vect map=admin_area color=<span><span>153:153:153</span></span> rgb_column=area_color display=shape type=area</span></div><div dir="ltr"><span>d.mon stop=png</span></div><div dir="ltr"><span><br clear="none"></span></div><div dir="ltr"><span>This only produces a png with the last vector listed and only the borders are colored with the rgb_column values.</span></div></div></div></blockquote><div><br clear="none"></div><div>I think you are missing GRASS_RENDER_FILE_READ=TRUE:</div><div><a shape="rect" href="https://grass.osgeo.org/grass78/manuals/pngdriver.html" rel="nofollow" target="_blank">https://grass.osgeo.org/grass78/manuals/pngdriver.html</a><br clear="none"></div><div><br clear="none"></div><div>Regarding rgb_column, I am not sure, didn't have time to test.</div><div><br clear="none"></div><div>Anna</div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><div><div style="font-family:Helvetica, Arial, sans-serif;font-size:16px;"><div id="ydpa9ae8044yiv7486881403gmail-m_2928144459414188663ydpe852ea3cyiv8557192743yqtfd86686"><div dir="ltr"><span><br clear="none"></span></div><div dir="ltr"><span>If I do this without the d.mon start/stop lines ... i.e. relying on the GRASS_RENDER_IMMEDIATE=png only, then only one vector map is converted to png however it DOES do the color fill properly. With either above method the png is the correct size.</span></div><div dir="ltr"><span><br clear="none"></span></div><div dir="ltr"><span>Now using ps.map (same env variable set as above):</span></div><div dir="ltr"><span><br clear="none"></span></div><div dir="ltr"><span><span>g.region vector='Country'</span><br clear="none"></span></div><div dir="ltr"><span>ps.map input=$HOME/ps_rules.txt out=<span><span><span><span><span><span>$HOME/country_admin.</span></span></span></span></span></span>ps --overwrite <br clear="none"></span></div><div dir="ltr"><span> where ps_rules.txt is:</span></div><div dir="ltr"><span></span>border y</div><div dir="ltr"> color 81:81:81</div><div dir="ltr"> end</div><div dir="ltr">vareas admin_area</div><div dir="ltr"> layer 1</div><div dir="ltr"> rgbcolumn area_color</div><div dir="ltr"> color 153:153:153</div><div dir="ltr"> end</div><div dir="ltr">vareas Country</div><div dir="ltr"> color 210:210:210</div><div dir="ltr"> fcolor 153:153:153</div><div dir="ltr"> end</div><div dir="ltr"><br clear="none"></div><div dir="ltr">We don't have pstopng but we do have ghostscript:</div><div dir="ltr"><br clear="none"></div><div dir="ltr">gs-dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r300 -sOutputFile=$HOME/<span><span><span><span><span><span><span><span>country_admin.</span></span></span></span></span></span>png $HOME/<span><span><span><span><span><span><span><span>country_admin.</span></span></span></span></span></span>p</span></span>s</span></span></div><div dir="ltr"><span><span><br clear="none"></span></span></div><div dir="ltr"><span><span>This creates the correct image (color fills, etc) but has white margins and a lot of white space below the image like<span><span><span> it is printed at the top of a piece of paper.</span></span></span></span></span></div><div dir="ltr"><span><span><span><span><span><br clear="none"></span></span></span></span></span></div><div dir="ltr"><span><span><span><span><span>does anyone have any idea how to create a png with multiple vector maps overlaying each other (and not have the extra whitespace too)?</span></span></span></span></span></div><div dir="ltr"><span><span><span><span><span><br clear="none"></span></span></span></span></span></div><div dir="ltr"><span><span><span><span><span>v/r</span></span></span></span></span></div></div><div dir="ltr"><div id="ydpa9ae8044yiv7486881403gmail-m_2928144459414188663ydpe852ea3cyiv8557192743yqtfd61097"><span><span><span><span><span>Chris</span></span></span></span></span></div><br clear="none"></div></div></div>_______________________________________________<br clear="none">
grass-user mailing list<br clear="none">
<a shape="rect" href="mailto:grass-user@lists.osgeo.org" rel="nofollow" target="_blank">grass-user@lists.osgeo.org</a><br clear="none">
<a shape="rect" href="https://lists.osgeo.org/mailman/listinfo/grass-user" rel="nofollow" target="_blank">https://lists.osgeo.org/mailman/listinfo/grass-user</a><div id="ydpa9ae8044yiv7486881403gmail-m_2928144459414188663ydpe852ea3cyiv8557192743yqtfd98045"><br clear="none">
</div></blockquote></div></div><div id="ydpa9ae8044yiv7486881403gmail-m_2928144459414188663ydpe852ea3cyiv8557192743yqtfd60384">
</div></div></div></div>
</div>
</div></div></blockquote></div></div></div><div class="ydpa9ae8044yiv7486881403yqt5532069994" id="ydpa9ae8044yiv7486881403yqtfd65040">
</div></div></div></div>
</div>
</div>
<div>_______________________________________________</div>
<div>grass-user mailing list</div>
<div><a class="aqm-autolink aqm-autowrap" href="mailto:grass-user%40lists.osgeo.org">grass-user@lists.osgeo.org</a></div>
<div><a class="aqm-autolink aqm-autowrap" href="https://lists.osgeo.org/mailman/listinfo/grass-user">https://lists.osgeo.org/mailman/listinfo/grass-user</a></div>
<div><br></div></blockquote>
</div>
</div>
<!-- body end -->
</div><div dir="auto"><br></div>
</div></body>
</html>