[GRASS-SVN] r63892 - grass/trunk/scripts/d.vect.thematic

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 1 05:01:58 PST 2015


Author: martinl
Date: 2015-01-01 05:01:58 -0800 (Thu, 01 Jan 2015)
New Revision: 63892

Modified:
   grass/trunk/scripts/d.vect.thematic/d.vect.thematic.html
   grass/trunk/scripts/d.vect.thematic/d.vect.thematic.py
Log:
d.vect.thematics: replace -u flag by rgb_column option (sync'ed with v.colors)
                  manual updated
                  check v.univar result


Modified: grass/trunk/scripts/d.vect.thematic/d.vect.thematic.html
===================================================================
--- grass/trunk/scripts/d.vect.thematic/d.vect.thematic.html	2015-01-01 12:07:46 UTC (rev 63891)
+++ grass/trunk/scripts/d.vect.thematic/d.vect.thematic.html	2015-01-01 13:01:58 UTC (rev 63892)
@@ -1,43 +1,52 @@
 <h2>DESCRIPTION</h2>
 
-<em>d.vect.thematic</em> creates thematic maps from vectors of
-all types and numeric attributes (stored in the data table connected to a vector
-map). Thematic maps can be displayed by either a graduated color scheme (for
-all vector types), as graduated icon sizes (for point and centroid types), or
-graduated line widths (for lines and boundaries with associated attributes).
-The user selects the vector map to be mapped and attribute column from which
-to derive mapping intervals, and (optionally) the layer for attribute data.
+<em>d.vect.thematic</em> creates thematic maps from vector features of
+all types and numeric attributes stored in the attribute table connected to a vector
+map.
 
-<p>In thematic maps, the color or point size changes for each range of attribute
-values. Value ranges for thematic mapping can be
-set at regular intervals, standard deviation units on either
-side of the mean, quartiles, or delimited by user-defined breakpoints.
-User-defined breakpoints also can  be entered, or piped into d.vect.thematic
-from standard input or other external source.
+<p>
+Thematic maps can be displayed by either a <i>graduated color
+scheme</i> (for all vector types), as <i>graduated icon sizes</i> (for
+point and centroid types), or <i>graduated line widths</i> (for lines
+and boundaries with associated attributes), see <b>themetype</b>
+option for details. The user selects the vector <b>map</b> to be
+mapped and attribute <b>column</b> from which to derive mapping
+intervals, and (optionally) the <b>layer</b> for attribute data.
 
-<p>There are options to define the color scheme (graduated
-colors) and range of point sizes (graduated points) for thematic maps. A
-simple text legend is printed. Optionally, a graphic legend can be drawn in
-the selected display monitor. Thematic colors can be uploaded to a GRASSRGB
-column for later display.
+<p>In thematic maps, the color or point size changes for each range of
+attribute values. Value ranges for thematic mapping can be set at
+<i>regular intervals</i>, <i>standard deviation</i> units on either side of the
+<i>mean</i>, <i>quartiles</i>, or delimited by <i>user-defined
+breakpoints</i>, see <b>themecalc</b> option.  User-defined
+breakpoints (<b>themecalc=custom_breaks</b>) can be entered
+via <b>breakpoints</b> option.
 
-<!-- outdated:
-,  and thematic map display commands can be saved to a
-group file (*.dm) that can be opened, edited, and displayed in
-the GIS Manager.
--->
+<h2>NOTES</h2>
 
-<p>When the psmap option is set to 'name', two psmap instruction files are
+<p>There is option <b>colorscheme</b> to define the color scheme
+(graduated colors) and range of point sizes (graduated points) for
+thematic maps.
+
+<p>
+Optionally, a simple text legend is printed when <b>-l</b> flag is
+given. A graphic legend can be drawn in the selected display monitor.
+
+<p>
+Thematic colors can be uploaded by <b>rgb_column</b> option
+to a specified attribute column (which is created automatically if
+doesn't exist in the table) for later display
+via <em><a href="d.vect.html">d.vect</a></em> and <b>rgb_column</b>
+option.
+
+<p>When the <b>psmap</b> option is set to 'name', two psmap instruction files are
 created (in the current directory if no path is given), one for the map
 ('name.psmap') and one for the legend ('name_legend.psmap'). The map file also
 contains 'label' commands which allow to create a legend directly in the map by
 adding a 'vlegend' command. See the <em><a href="ps.map">ps.map</a></em> manual
 page for more details.
-
-
-<h2>NOTES</h2>
-
-The algorithm currently uses the <em>v.univar</em> to calculate basic
+ 
+<p>
+The algorithm currently uses the <em><a href="v.univar.html">v.univar</a></em> to calculate basic
 descriptive statistics needed for thematic mapping (minimum, maximum, mean,
 standard deviation, and quartiles).
 
@@ -103,7 +112,13 @@
 
 <h2>AUTHORS</h2>
 
-Michael Barton, Arizona State University, Daniel Cavelo Aros,
-Martin Landa, and Jachym Cepicky.
+Michael Barton, Arizona State University
 
-<p><i>Last changed: $Date: 2008-08-15 08:16:42 +0200 (Fri, 15 Aug 2008)$</i>
+<p>
+Various updates by:<br>
+Daniel Cavelo Aros,<br>
+Martin Landa,<br>
+Jachym Cepicky.
+
+<p>
+  <i>Last changed: $Date: 2008-08-15 08:16:42 +0200 (Fri, 15 Aug 2008)$</i>

Modified: grass/trunk/scripts/d.vect.thematic/d.vect.thematic.py
===================================================================
--- grass/trunk/scripts/d.vect.thematic/d.vect.thematic.py	2015-01-01 12:07:46 UTC (rev 63891)
+++ grass/trunk/scripts/d.vect.thematic/d.vect.thematic.py	2015-01-01 13:01:58 UTC (rev 63892)
@@ -17,7 +17,7 @@
 
 
 #%module
-#% description: Displays thematic vector map
+#% description: Displays thematic map created from vector features and numeric attributes.
 #% keyword: display
 #% keyword: cartography
 #% keyword: vector
@@ -35,6 +35,9 @@
 #%option G_OPT_V_TYPE
 #% answer: area
 #%end
+#%option G_OPT_DB_WHERE
+#% guisection: Theme
+#%end
 #%option
 #% key: themetype
 #% type: string
@@ -155,9 +158,6 @@
 #% key: g
 #%description: Save thematic map commands to group file for GIS Manager
 #%end
-#%option G_OPT_DB_WHERE
-#% guisection: Theme
-#%end
 #%option
 #% key: psmap
 #% type: string
@@ -171,6 +171,10 @@
 #% required: no
 #% guisection: Files
 #%end
+#%option G_OPT_DB_COLUMN
+#% key: rgb_column
+#% description: Name of color column to populate RGB values
+#%end
 #%flag 
 #% guisection: Theme
 #%key: l
@@ -181,11 +185,6 @@
 #% key: f
 #% description: Only draw fills (no outlines) for areas and points
 #%end
-#%flag
-#% guisection: Color
-#% key: u
-#% description: Update color values to GRASSRGB column in attribute table
-#%end
 #%flag 
 #% guisection: Misc
 #%key: s
@@ -222,9 +221,12 @@
 def subs(vars, tmpl):
     return string.Template(tmpl).substitute(vars)
 
-def msg(vars, tmpl):
-    grass.message(subs(vars, tmpl))
-
+def msg(vars, tmpl, verbose=False):
+    if not verbose:
+        grass.message(subs(vars, tmpl))
+    else:
+        grass.verbose(subs(vars, tmpl))
+        
 def out(fh, vars, tmpl):
     fh.write(subs(vars, tmpl))
 
@@ -251,13 +253,13 @@
     type = options['type']
     where = options['where']
     icon = options['icon']
-
+    rgb_column = options['rgb_column']
+    
     flag_f = flags['f']
     flag_g = flags['g']
     flag_l = flags['l']
     flag_m = flags['m']
     flag_s = flags['s']
-    flag_u = flags['u']
 
     layer = int(layer)
     nint = int(nint)
@@ -307,12 +309,12 @@
     driver = db['driver']
 
     # update color values to the table?
-    if flag_u:
-        # test, if the column GRASSRGB is in the table
+    if rgb_column:
+        # test, if the rgb column is in the table
         s = grass.read_command('db.columns', table = table, database = database, driver = driver)
-        if 'grassrgb' not in s.splitlines():
-            msg(locals(), _("Creating column 'grassrgb' in table <$table>"))
-            sql = "ALTER TABLE %s ADD COLUMN grassrgb varchar(11)" % table
+        if rgb_column not in s.splitlines():
+            msg(locals(), _("Creating column <$rgb_column> in table <$table>"))
+            sql = "ALTER TABLE %s ADD COLUMN %s varchar(11)" % (table, rgb_column)
             grass.write_command('db.execute', database = database, driver = driver, input = '-', stdin = sql)
 
     # Group name
@@ -328,12 +330,14 @@
     else:
         stype = ["point", "centroid"]
 
-    if not where:
-        where = None
-
     stats = grass.read_command('v.univar', flags = 'eg', map = map, type = stype, column = column, where = where, layer = layer)
+    if not stats:
+        grass.fatal(_("Unable to calculate statistics for vector map <%s>" % map))
     stats = grass.parse_key_val(stats)
-
+    if 'min' not in stats:
+        grass.fatal(_("Unable to calculate statistics for vector map <%s> "
+                      "(missing minimum/maximum value)" % map))
+        
     min  = float(stats['min'])
     max  = float(stats['max'])
     mean = float(stats['mean'])
@@ -368,7 +372,7 @@
         annotations = " %f; %f; %f; %f" % (q1, q2, q3, q4)
     elif themecalc == "custom_breaks":
         if not breakpoints:
-            breakpoints = sys.stdin.read()
+            grass.fatal(_("Required parameter <%s> not set") % "breakpoints") 
         breakpoints = [int(x) for x in breakpoints.split()]
         numint = len(breakpoints) - 1
         annotations = ""
@@ -412,7 +416,7 @@
 end
 """)
 
-    msg(locals(), _("Thematic map legend for column $column of map $map"))
+    msg(locals(), _("Thematic map legend for column <$column> of map <$map>"), verbose=True)
     msg(locals(), _("Value range: $min - $max"))
 
     colorschemes = {
@@ -668,8 +672,8 @@
                 sqlwhere = subs(locals(), "$column $mincomparison $rangemin AND $column <= $rangemax AND $where")
 
             # update color to database?
-            if flag_u:
-                sql = subs(locals(), "UPDATE $table SET GRASSRGB = '$themecolor' WHERE $sqlwhere")
+            if rgb_column:
+                sql = subs(locals(), "UPDATE $table SET $rgb_column = '$themecolor' WHERE $sqlwhere")
                 grass.write_command('db.execute', database = database, driver = driver, input = '-', stdin = sql)
 
             # Create group for GIS Manager
@@ -730,7 +734,8 @@
 
             grass.run_command('d.vect', map = map, type = type, layer = layer,
                               where = sqlwhere,
-                              color = linecolor, fcolor = themecolor, icon = icon, size = ptsize)
+                              color = linecolor, fcolor = themecolor, icon = icon, size = ptsize,
+                              quiet = True)
 
             if type in ["line", "boundary"]:
                 out(f_psmap, locals(), """\
@@ -984,8 +989,8 @@
                 sqlwhere = subs(locals(), "$column $mincomparison $rangemin AND $column <= $rangemax AND $where")
 
             # update color to database?
-            if flag_u:
-                sql = subs(locals(), "UPDATE $table SET grassrgb = '$themecolor' WHERE $sqlwhere")
+            if rgb_column:
+                sql = subs(locals(), "UPDATE $table SET $rgb_column = '$themecolor' WHERE $sqlwhere")
                 grass.write_command('db.execute', database = database, driver = driver, input = '-', stdin = sql)
 
             # Create group for GIS Manager



More information about the grass-commit mailing list