[GRASS-SVN] r63904 - in grass/branches/releasebranch_7_0: . scripts/d.vect.thematic

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 1 10:23:38 PST 2015


Author: martinl
Date: 2015-01-01 10:23:38 -0800 (Thu, 01 Jan 2015)
New Revision: 63904

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/scripts/d.vect.thematic/d.vect.thematic.html
   grass/branches/releasebranch_7_0/scripts/d.vect.thematic/d.vect.thematic.py
Log:
d.vect.thematic: check if monitor or direct rendering is enabled
                 fix calculating range min/max
                 skip rgb_column if not map not found in current mapset
                 be quiet when --q is given
                 fix interval count
                 replace -u flag by rgb_column option (sync'ed with v.colors)
                 manual updated
                 check v.univar result
                 (merge r63892-4, r63902-3 from trunk)



Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:60817,61096,61141,61994,62105,62179-62180,62182,62190,62403,62422,62424,62437,62466,62469,62487,62491,62494,62501,62506,62508-62509,62515,62518-62519,62521,62526,62533,62539,62541,62555,62562,62566,62570,62573,62575,62585,62588,62597,62603,62606,62608-62609,62614,62618,62628,62632,62638,62642,62648-62649,62652,62654-62657,62666,62691,62705,62709,62723,62730,62739,62741,62743,62746,62750-62752,62757,62762,62785,62798,62800-62801,62803,62805,62812,62822,62824,62828,62831,62838,62845,62847,62850,62856,62879,62881,62886,62904,62907-62908,62910,62912,62914,62916,62918,62920,62925,62932-62933,62935,62940,62942,62944-62946,62949,62955-62956,62958,62960,62962,62964,62966-62968,62970,62973,62975,62977,62981,62983,62985,62987,62989,62991,62993,62995,62997,62999-63000,63003,63005,63007,63009,63011,63013,63015,63017,63020,63022,63024,63026,63028-63031,63033,63035,63037,63040,63043-63044,63047,63049,63051,63053,63055,63057,63060,63062-63064,63066,63068,63070-63071,63074,
 63076,63079,63081,63083,63085,63087,63089,63091,63093,63095,63098,63100,63102,63105,63107,63109,63111,63113-63114,63116,63119,63121,63123,63125,63130,63132-63133,63135,63137,63140,63143,63145,63147,63149,63151,63153-63154,63157,63160,63165,63170,63173,63175,63187,63192-63193,63196,63199-63200,63202,63209,63216,63220-63221,63224,63227,63240,63246,63250,63255,63259,63261,63275-63276,63279,63281,63283,63287,63290,63292,63297,63302,63304-63307,63315,63319,63327,63330,63332,63339,63342,63345,63361-63363,63367,63379,63389,63391,63393,63402,63408-63409,63416-63417,63425,63427,63429,63431,63433,63448,63451,63453,63457,63459,63464-63470,63473,63482,63497,63505,63508,63510,63515,63521-63524,63526,63536-63537,63551-63552,63554,63556,63558-63559,63562,63570,63576,63582,63589-63593,63602,63604,63608-63609,63616,63618,63624,63626,63628,63630,63634,63639,63642,63644,63650,63652,63656,63679,63685,63689,63691,63693,63695,63698,63700-63702,63704,63706-63707,63709,63711,63713,63715,63717-63718
 ,63721-63727,63731,63733,63740-63742,63744,63747-63749,63751-63752,63756,63758,63761,63767,63777,63780,63783,63787,63793,63796-63798,63801,63803,63807-63808,63812,63814,63816,63821,63823-63824,63827-63828,63830-63831,63834-63835,63837-63839,63841,63843-63844,63846-63847,63849,63851,63853,63855-63856,63858-63859,63862,63865,63869,63871,63882,63884,63889-63890,63895,63897-63898,63900
   + /grass/trunk:60817,61096,61141,61994,62105,62179-62180,62182,62190,62403,62422,62424,62437,62466,62469,62487,62491,62494,62501,62506,62508-62509,62515,62518-62519,62521,62526,62533,62539,62541,62555,62562,62566,62570,62573,62575,62585,62588,62597,62603,62606,62608-62609,62614,62618,62628,62632,62638,62642,62648-62649,62652,62654-62657,62666,62691,62705,62709,62723,62730,62739,62741,62743,62746,62750-62752,62757,62762,62785,62798,62800-62801,62803,62805,62812,62822,62824,62828,62831,62838,62845,62847,62850,62856,62879,62881,62886,62904,62907-62908,62910,62912,62914,62916,62918,62920,62925,62932-62933,62935,62940,62942,62944-62946,62949,62955-62956,62958,62960,62962,62964,62966-62968,62970,62973,62975,62977,62981,62983,62985,62987,62989,62991,62993,62995,62997,62999-63000,63003,63005,63007,63009,63011,63013,63015,63017,63020,63022,63024,63026,63028-63031,63033,63035,63037,63040,63043-63044,63047,63049,63051,63053,63055,63057,63060,63062-63064,63066,63068,63070-63071,63074,
 63076,63079,63081,63083,63085,63087,63089,63091,63093,63095,63098,63100,63102,63105,63107,63109,63111,63113-63114,63116,63119,63121,63123,63125,63130,63132-63133,63135,63137,63140,63143,63145,63147,63149,63151,63153-63154,63157,63160,63165,63170,63173,63175,63187,63192-63193,63196,63199-63200,63202,63209,63216,63220-63221,63224,63227,63240,63246,63250,63255,63259,63261,63275-63276,63279,63281,63283,63287,63290,63292,63297,63302,63304-63307,63315,63319,63327,63330,63332,63339,63342,63345,63361-63363,63367,63379,63389,63391,63393,63402,63408-63409,63416-63417,63425,63427,63429,63431,63433,63448,63451,63453,63457,63459,63464-63470,63473,63482,63497,63505,63508,63510,63515,63521-63524,63526,63536-63537,63551-63552,63554,63556,63558-63559,63562,63570,63576,63582,63589-63593,63602,63604,63608-63609,63616,63618,63624,63626,63628,63630,63634,63639,63642,63644,63650,63652,63656,63679,63685,63689,63691,63693,63695,63698,63700-63702,63704,63706-63707,63709,63711,63713,63715,63717-63718
 ,63721-63727,63731,63733,63740-63742,63744,63747-63749,63751-63752,63756,63758,63761,63767,63777,63780,63783,63787,63793,63796-63798,63801,63803,63807-63808,63812,63814,63816,63821,63823-63824,63827-63828,63830-63831,63834-63835,63837-63839,63841,63843-63844,63846-63847,63849,63851,63853,63855-63856,63858-63859,63862,63865,63869,63871,63882,63884,63889-63890,63892-63895,63897-63898,63900,63902-63903

Modified: grass/branches/releasebranch_7_0/scripts/d.vect.thematic/d.vect.thematic.html
===================================================================
--- grass/branches/releasebranch_7_0/scripts/d.vect.thematic/d.vect.thematic.html	2015-01-01 17:39:04 UTC (rev 63903)
+++ grass/branches/releasebranch_7_0/scripts/d.vect.thematic/d.vect.thematic.html	2015-01-01 18:23:38 UTC (rev 63904)
@@ -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/branches/releasebranch_7_0/scripts/d.vect.thematic/d.vect.thematic.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/d.vect.thematic/d.vect.thematic.py	2015-01-01 17:39:04 UTC (rev 63903)
+++ grass/branches/releasebranch_7_0/scripts/d.vect.thematic/d.vect.thematic.py	2015-01-01 18:23:38 UTC (rev 63904)
@@ -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
@@ -33,8 +33,11 @@
 #% required: yes
 #%end
 #%option G_OPT_V_TYPE
-#% answer: area
+#%answer: point,line,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,19 +253,32 @@
     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)
     size = float(size)
     maxsize = float(maxsize)
 
+    if 'MONITOR' not in grass.gisenv().keys() and \
+       'GRASS_RENDER_IMMEDIATE' not in os.environ:
+       grass.fatal(_("Neither MONITOR (managed by d.mon command) nor GRASS_RENDER_IMMEDIATE "
+                     "(used for direct rendering) defined)"))
+            
+    mapset = grass.find_file(map, element='vector')['mapset']
+    if not mapset:
+        grass.fatal(_("Vector map <%s> not found") % map)
+    if rgb_column and mapset != grass.gisenv()['MAPSET']:
+        grass.warning(_("Vector map <%s> not found in the current mapset. "
+                        "Updating RGB values <%s> skipped.") % (map, "rgb_column"))
+        rgb_column = None
+
     # check column type
     inf = grass.vector_columns(map, layer)
     if column not in inf:
@@ -307,12 +322,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 +343,15 @@
     else:
         stype = ["point", "centroid"]
 
-    if not where:
-        where = None
-
+    grass.message(_("Calculating statistics..."))
     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 +386,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 +430,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 = {
@@ -429,7 +447,7 @@
 
     # open file for psmap instructions
     f_psmap = file(tmp_psmap, 'w')
-
+    
     # graduated color thematic mapping
     if themetype == "graduated_colors":
         if colorscheme in colorschemes:
@@ -534,17 +552,17 @@
   ref bottom left
 end
 """)
+        
+        grass.message("")
+        grass.message(_("Color(R:G:B)\tValue"))
+        grass.message("============\t==========")
 
-        sys.stdout.write("Color(R:G:B)\tValue\n")
-        sys.stdout.write("============\t==========\n")
-
         line1 = 78
         line2 = 76
         line3 = 75
 
-        i = 1
+        i = 0
         first = True
-
         while i < numint:
             if flag_m:
                 # math notation
@@ -555,7 +573,7 @@
                     first = False
                 else:
                     closebracket = "]"
-                    openbracket = "]"
+                    openbracket = "["
                     mincomparison = ">"
             else:
                 closebracket = "" 
@@ -565,7 +583,7 @@
                     first = False
                 else:
                     mincomparison = ">"
-
+            
             themecolor = ":".join(__builtins__.map(str,color))
             if flag_f:
                 linecolor = "none"
@@ -575,9 +593,12 @@
                 else:
                     linecolor = linecolor
 
-            rangemin = __builtins__.min(breakpoints)
-            rangemax = __builtins__.max(breakpoints)
-
+            ### ???
+            ### rangemin = __builtins__.min(breakpoints)
+            ### rangemax = __builtins__.max(breakpoints)
+            rangemin = breakpoints[i]
+            rangemax = breakpoints[i+1]
+            
             if not annotations:
                 extranote = ""
             else:
@@ -661,15 +682,15 @@
 
                 f_gisleg.write("text - - - {...}\n")
 
-            sys.stdout.write(subs(locals(), "$themecolor\t\t$openbracket$rangemin - $rangemax$closebracket $extranote\n"))
+            grass.message("%-15s %s%.3f - %.3f%s %s" % (themecolor, openbracket, rangemin, rangemax, closebracket, extranote))
             if not where:
                 sqlwhere = subs(locals(), "$column $mincomparison $rangemin AND $column <= $rangemax")
             else:
                 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 +751,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(), """\
@@ -770,7 +792,7 @@
             if i == numint:
                 color = endcolor
             else:
-                color = [a - b for a, b in zip(color, clrstep)]
+                color = [__builtins__.min(a - b, 255) for a, b in zip(color, clrstep)]
             line1 -= 4
             line2 -= 4
             line3 -= 4
@@ -868,8 +890,9 @@
 """)
 
 
-        sys.stdout.write("Size/width\tValue\n")
-        sys.stdout.write("==========\t=====\n")
+        grass.message("")
+        grass.message(_("Size/width\tValue"))
+        grass.message("==========\t=====")
 
         themecolor = pointcolor
 
@@ -903,8 +926,11 @@
             if flag_f:
                 linecolor = "none"
 
-            rangemin = __builtins__.min(breakpoints)
-            rangemax = __builtins__.max(breakpoints)
+            ### ???
+            ### rangemin = __builtins__.min(breakpoints)
+            ### rangemax = __builtins__.max(breakpoints)
+            rangemin = breakpoints[i-1]
+            rangemax = breakpoints[i]
 
             if not annotations:
                 extranote = ""
@@ -976,7 +1002,8 @@
 end
 """)
 
-            sys.stdout.write(subs(locals(), "$ptsize\t\t$openbracket$rangemin - $rangemax$closebracket $extranote\n"))
+            grass.message("%-15d %s%.3f - %.3f%s %s" % \
+                          (ptsize, openbracket, rangemin, rangemax, closebracket, extranote))
 
             if not where:
                 sqlwhere = subs(locals(), "$column $mincomparison $rangemin AND $column <= $rangemax")
@@ -984,8 +1011,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
@@ -1038,17 +1065,16 @@
 
             #graduates line widths or point sizes
 
+            kwargs = {}
             if themetype == "graduated_lines":
-                grass.run_command('d.vect', map = map, type = type, layer = layer,
-                                  where = sqlwhere,
-                                  color = linecolor, fcolor = themecolor, icon = icon, size = ptsize,
-                                  width = ptsize)
-
-            else:
-                grass.run_command('d.vect', map = map, type = type, layer = layer,
-                                  where = sqlwhere,
-                                  color = linecolor, fcolor = themecolor, icon = icon, size = ptsize)
-
+                kwargs['width'] = ptsize
+                
+            grass.run_command('d.vect', map = map, type = type, layer = layer,
+                              where = sqlwhere,
+                              color = linecolor, fcolor = themecolor, icon = icon,
+                              size = ptsize, quiet = True, **kwargs)
+            
+            if themetype != "graduated_lines":
                 out(f_psmap, locals(), """\
 vpoints $map
   type $type



More information about the grass-commit mailing list