[GRASS-SVN] r67361 - grass-addons/grass7/raster/r.out.legend
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Dec 24 06:04:03 PST 2015
Author: pvanbosgeo
Date: 2015-12-24 06:04:03 -0800 (Thu, 24 Dec 2015)
New Revision: 67361
Added:
grass-addons/grass7/raster/r.out.legend/r_out_legend_5.png
Modified:
grass-addons/grass7/raster/r.out.legend/r.out.legend.html
grass-addons/grass7/raster/r.out.legend/r.out.legend.py
Log:
Option to include histogram added
Modified: grass-addons/grass7/raster/r.out.legend/r.out.legend.html
===================================================================
--- grass-addons/grass7/raster/r.out.legend/r.out.legend.html 2015-12-24 13:04:08 UTC (rev 67360)
+++ grass-addons/grass7/raster/r.out.legend/r.out.legend.html 2015-12-24 14:04:03 UTC (rev 67361)
@@ -1,16 +1,18 @@
<h2>DESCRIPTION</h2>
-The <em>r.out.legend</em> script provides a convenient way
-to quickly create a smoothed legend image for floating point raster maps
-(continuous values as opposed to categories), with the dimensions and
-resolution required. It is furthermore possible to set the font (default
-is 'Arial') and font size (default=10). The legend can be saved as
+The <em>r.out.legend</em> script provides a convenient way to
+quickly create a smoothed legend image for floating point raster
+maps (continuous values as opposed to categories), with the
+dimensions and resolution required. Optionally, a histogram can be
+added along side the legend by setting the -d flag. It is
+furthermore possible to set the font (default is 'Arial') and font
+size (default=10). The legend can be saved as
<a href="https://grass.osgeo.org/grass64/manuals/pngdriver.html">PNG</a>,
<a href="https://grass.osgeo.org/grass64/manuals/psdriver.html">PS</a>
-(postscript), BMP, PPM, PDF AND SVG. The latter four are supported through the
-Cairo driver (see Notes). The images can be used to add a continuous
-legends in maps created in e.g., QGIS composer or as part of a
-Google Earth map.
+(postscript), BMP, PPM, PDF AND SVG. The latter four are supported
+through the Cairo driver (see Notes). The images can be used to add
+a continuous legends in maps created in e.g., QGIS composer or as
+part of a Google Earth map.
<h2>NOTES</h2>
@@ -25,6 +27,22 @@
-f flag, see <em>d.legend</em>).
<p>
+The user may create a horizontal legend by making the box wider
+than it is tall. Note that for vertical legends labels are placed to
+the right of the legend box. For horizontal legends the text will
+be places below the legend.
+
+<p> The -d flag is used to display a histogram distribution along
+side the legend. For vertical legends, the histogram will be placed
+left of the legend; if horizontal, it will be placed above the
+legend bar. The histogram is 1.75 x the width (or height if
+horizontal) of the legend bar. This thus adds to the final width of
+the output image. Note that the statistics are calculated on the
+current computational region settings set by g.region. The default
+range however covers the entire natural bounds of the input map. If
+the histogram appears empty, check your region settings.
+
+<p>
The script is a wrapper of <a href="https://grass.osgeo.org/grass71/manuals/d.mon.html">d.mon</a>
and <a href="https://grass.osgeo.org/grass71/manuals/d.legend.html"> d.legend</a>.
For detailed explanations of the different options,
@@ -42,12 +60,6 @@
anti-aliasing, which might give nicer results (smoother lines and
numbers). Compare the output for example 1 and 4.
-<p>
-The user may create a horizontal legend by making the box wider
-than it is tall. Note that for vertical legends labels are placed to
-the right of the legend box. For horizontal legends the text will
-be places below the legend.
-
<p> The default resolution is 300 px/inch (ppi), except when the unit is
set to <em>px</em>, in which case the default resolution is set to
96 ppi.
@@ -142,7 +154,45 @@
<p><img src="r_out_legend_4.png">
+<p>
+The dimensions (width and height) of the image:
+<div class="code"><pre>
+----------------------------
+File saved as r_out_legend_4.png
+The image dimensions are:
+286px wide and 50px heigh
+at a resolution of 150 ppi this is:
+4.84293333333 cm x 0.855133333333 cm
+----------------------------
+</pre></div>
+
+<h3>Example 5</h3>
+
+Like example 4, but adding a histogram. Note that the histogram adds
+to the size of the image (while the dimensions of the bar remain the
+same as in the previous example).
+
+<div class="code"><pre>
+r.out.legend raster=elevation file=r_out_legend_5.png filetype=cairo \
+ dimensions=4,0.4 labelnum=3 fontsize=7 unit="cm" resolution=150 -d
+</pre></div
+
+<p><img src="r_out_legend_5.png">
+
+<p>
+The dimensions (width and height) of the image:
+
+<div class="code"><pre>
+----------------------------
+File saved as r_out_legend_5.png
+The image dimensions are:
+286px wide and 92px heigh
+at a resolution of 150 ppi this is:
+4.84293333333 cm x 1.56633333333 cm
+----------------------------
+</pre></div>
+
<h2>SEE ALSO</h2>
<em><a href="d.mon.html">d.mon</a></em>,
Modified: grass-addons/grass7/raster/r.out.legend/r.out.legend.py
===================================================================
--- grass-addons/grass7/raster/r.out.legend/r.out.legend.py 2015-12-24 13:04:08 UTC (rev 67360)
+++ grass-addons/grass7/raster/r.out.legend/r.out.legend.py 2015-12-24 14:04:03 UTC (rev 67361)
@@ -122,6 +122,11 @@
#% guisection: Extra options
#%end
+#%flag:
+#% key: d
+#% description: Add histogram to legend
+#% guisection: Extra options
+#%end
#------------------------------------------------------------------------------
@@ -191,40 +196,49 @@
fontsize = int(options['fontsize'])
digits = int(options['digits'])
flag_f = flags['f']
+ flag_d = flags['d']
# Check if input layer exists
CheckLayer(inmap)
# Compute output size of legend bar in pixels
if unit=='cm':
- w = math.ceil(float(width)/2.54*float(resol)) + 3
- h = math.ceil(float(height)/2.54*float(resol)) + 3
+ bw = math.ceil(float(width)/2.54*float(resol))
+ bh = math.ceil(float(height)/2.54*float(resol))
elif unit=='mm':
- w = math.ceil(float(width)/25.4*float(resol)) + 3
- h = math.ceil(float(height)/25.4*float(resol)) + 3
+ bw = math.ceil(float(width)/25.4*float(resol))
+ bh = math.ceil(float(height)/25.4*float(resol))
elif unit=='inch':
- w = math.ceil(width*resol) + 6
- h = math.ceil(height*resol) + 6
+ bw = math.ceil(float(width)*float(resol))
+ bh = math.ceil(float(height)*float(resol))
elif unit=="px":
- w=float(width) + 6
- h=float(height) + 6
+ bw=float(width)
+ bh=float(height)
else:
grass.error('Unit must be inch, cm, mm or px')
- # Margins
- mw = 2 / w * 100
- mh = 2 / h * 100
+ # Add size of legend to w or h, if flag_d is set
+ if flag_d:
+ if float(height)>float(width):
+ w = bw * 2.75 + 4
+ h = bh + 4
+ else:
+ h = bh * 2.75 + 4
+ w = bw + 4
+ else:
+ w = bw + 4
+ h = bh + 4
- # Check if fontsize = 0 ( = no raster values)
+ # Determine image width and height
if fontsize==0:
- iw = w
- ih = h
- fz = 1
+ iw = w; ih = h; fz = 1
+ mw = 2 / w * 100
+ mh = 2 / h * 100
at = str(mw) + "," + str(100-mw) + "," + str(mh) + "," + str(100-mh)
else:
fz = round(float(fontsize) * (float(resol)/72.272))
- # Compute image position and position
+ # Allow for extra space at left (low) side if number with digits
maprange = grass.raster_info(inmap)
maxval = round(maprange['max'],digits)
if maxval<1:
@@ -232,9 +246,15 @@
else:
maxl=len(str(maxval)) - 2
+ # Page width and height + position bar
if float(height)>float(width):
- iw = w + fz * maxl
- ih = h
+ iw = w + fz * maxl; ih = h
+ if flag_d:
+ mw = (2 + (bw * 1.75)) / iw * 100
+ mh = 2 / ih * 100
+ else:
+ mw = 2 / iw * 100
+ mh = 2 / ih * 100
at = str(mh) + "," + str(100-mh) + "," + str(mw) + "," + str((100*w/iw)-1)
else:
minval = round(maprange['min'],digits)
@@ -242,6 +262,12 @@
margin_right = 0.5 * maxl
iw = w + fz * (margin_left + margin_right)
ih = h + fz * 1.5
+ if flag_d:
+ mh = (2 + (bh * 1.75)) / ih * 100
+ mw = 2 / iw * 100
+ else:
+ mw = 2 / w * 100
+ mh = 2 / h * 100
at = str(100 - (100*h/ih)) + "," + str(100-mh) + "," + \
str((100 * fz * margin_left / iw)) + "," + \
str(100 - (100 * fz * margin_right / iw))
@@ -257,6 +283,8 @@
flag='csv'
else:
flag='sv'
+ if flag_d:
+ flag=flag + 'd'
if val_range=='':
grass.run_command("d.legend", flags=flag, raster=inmap, font=font,
at=at, fontsize=fz, labelnum=labelnum)
@@ -298,3 +326,14 @@
+
+
+
+
+
+
+
+
+
+
+
Added: grass-addons/grass7/raster/r.out.legend/r_out_legend_5.png
===================================================================
(Binary files differ)
Property changes on: grass-addons/grass7/raster/r.out.legend/r_out_legend_5.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
More information about the grass-commit
mailing list