[GRASS-SVN] r72915 - in grass-addons/grass7/display: . d.vect.colhist

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 26 09:08:47 PDT 2018


Author: mlennert
Date: 2018-06-26 09:08:47 -0700 (Tue, 26 Jun 2018)
New Revision: 72915

Added:
   grass-addons/grass7/display/d.vect.colhist/
   grass-addons/grass7/display/d.vect.colhist/Makefile
   grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.html
   grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.py
   grass-addons/grass7/display/d.vect.colhist/d_vect_colhist.png
Log:
New addon d.vect.colhist: Draws the histogram of values in a vector attribute column

Added: grass-addons/grass7/display/d.vect.colhist/Makefile
===================================================================
--- grass-addons/grass7/display/d.vect.colhist/Makefile	                        (rev 0)
+++ grass-addons/grass7/display/d.vect.colhist/Makefile	2018-06-26 16:08:47 UTC (rev 72915)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = d.vect.colhist
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.html
===================================================================
--- grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.html	                        (rev 0)
+++ grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.html	2018-06-26 16:08:47 UTC (rev 72915)
@@ -0,0 +1,32 @@
+<h2>DESCRIPTION</h2>
+
+<p>
+<em>d.vect.colhist</em> draws a histogram of the values in a vector 
+<em>map</em> attribute <em>column</em>. The user use the <em>where</em>
+option to only select a subset of the attribute table and can determine the 
+number of <em>bins</em> (bars) used for the histogram. The <em>plot_output</em>
+parameter determines whether the result is displayed on screen (default) or
+exported to a graphics file.
+
+<h2>NOTE</h2>
+<p>
+This is a quick and dirty solution using basic matplotlib. In future, this 
+should be integrated into the g.gui, possibly together with the raster 
+histogram tool.
+
+<h2>EXAMPLE</h2>
+
+Show the histogram of median age values in the census block map:
+<div class="code"><pre>
+d.vect.colhist map=censusblk_swwake column=MEDIAN_AGE where="TOTAL_POP>0"
+</pre></div>
+
+<center>
+	                <img src="d_vect_colhist.png" border="1"><br>
+	                Histogram of median age values of census blocks
+</center>
+
+<h2>AUTHOR</h2>
+ Moritz Lennert
+
+<p><i>Last changed: $Date: 2016-11-24 11:04:02 +0100 (jeu 24 nov 2016) $</i>

Added: grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.py
===================================================================
--- grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.py	                        (rev 0)
+++ grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.py	2018-06-26 16:08:47 UTC (rev 72915)
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE:       d.vect.colhist 
+# AUTHOR:       Moritz Lennert
+# PURPOSE:      Draws the histogram of values in a vector attribute column
+#
+# COPYRIGHT:    (c) 2017 Moritz Lennert, and the GRASS Development Team
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%module
+#% description: Draws the histogram of values in a vector attribute column
+#% keyword: display
+#% keyword: vector
+#% keyword: geology
+#%end
+#%option G_OPT_V_MAP
+#%end
+#%option G_OPT_DB_COLUMN
+#% key: column
+#% description: Attribute column containing azimuth
+#% required: yes
+#%end
+#%option G_OPT_DB_WHERE
+#%end
+#%option G_OPT_F_OUTPUT
+#% key: plot_output
+#% label: Name for graphic output file for plot (extension decides format, - for screen)
+#% required: yes
+#% answer: -
+#%end
+#%option
+#% key: bins
+#% type: integer
+#% description: Number of bins in histogram
+#% answer: 30
+#% required: no
+#%end
+
+
+import sys
+import matplotlib #required by windows
+matplotlib.use('wxAGG') #required by windows
+import matplotlib.pyplot as plt
+import grass.script as gscript
+
+
+def main():
+    vector = options['map']
+    column = options['column']
+    bins = int(options['bins'])
+    plot_output = options['plot_output']
+    where = options['where'] if options['where'] else None
+
+    if where:
+        data=[float(x) for x in gscript.read_command('v.db.select',
+                                                     map_=vector,
+                                                     column=column,
+                                                     where=where,
+                                                     flags='c').splitlines()]
+    else:
+        data=[float(x) for x in gscript.read_command('v.db.select',
+                                                     map_=vector,
+                                                     column=column,
+                                                     flags='c').splitlines()]
+   
+    plt.hist(data, bins=bins)
+    if plot_output == '-':
+	plt.show()
+    else:
+	plt.savefig(plot_output)
+
+if __name__ == "__main__":
+    options, flags = gscript.parser()
+    main()
+


Property changes on: grass-addons/grass7/display/d.vect.colhist/d.vect.colhist.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: grass-addons/grass7/display/d.vect.colhist/d_vect_colhist.png
===================================================================
(Binary files differ)

Index: grass-addons/grass7/display/d.vect.colhist/d_vect_colhist.png
===================================================================
--- grass-addons/grass7/display/d.vect.colhist/d_vect_colhist.png	2018-06-26 12:43:13 UTC (rev 72914)
+++ grass-addons/grass7/display/d.vect.colhist/d_vect_colhist.png	2018-06-26 16:08:47 UTC (rev 72915)

Property changes on: grass-addons/grass7/display/d.vect.colhist/d_vect_colhist.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property


More information about the grass-commit mailing list