[GRASS-SVN] r37045 - grass/branches/develbranch_6/ps/ps.map

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 8 02:16:06 EDT 2009


Author: hamish
Date: 2009-05-08 02:16:03 -0400 (Fri, 08 May 2009)
New Revision: 37045

Modified:
   grass/branches/develbranch_6/ps/ps.map/colortable.h
   grass/branches/develbranch_6/ps/ps.map/description.html
   grass/branches/develbranch_6/ps/ps.map/ps_clrtbl.c
   grass/branches/develbranch_6/ps/ps.map/ps_fclrtbl.c
   grass/branches/develbranch_6/ps/ps.map/ps_map.c
   grass/branches/develbranch_6/ps/ps.map/r_colortable.c
Log:
add option to allow FP maps to use discrete color bands as specified in the map's cats/ file

Modified: grass/branches/develbranch_6/ps/ps.map/colortable.h
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/colortable.h	2009-05-08 05:57:44 UTC (rev 37044)
+++ grass/branches/develbranch_6/ps/ps.map/colortable.h	2009-05-08 06:16:03 UTC (rev 37045)
@@ -9,7 +9,7 @@
 {
     double x, y, width;
     double min, max;
-    double height;		/* fp legend height */
+    double height;	/* fp legend height */
     char *font;
     char *name;
     char *mapset;
@@ -18,6 +18,7 @@
     int cols;
     int nodata;
     int tickbar;
+    int discrete;	/* for FP maps use discrete bands not continuous gradient */
     int range_override;
 };
 

Modified: grass/branches/develbranch_6/ps/ps.map/description.html
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/description.html	2009-05-08 05:57:44 UTC (rev 37044)
+++ grass/branches/develbranch_6/ps/ps.map/description.html	2009-05-08 06:16:03 UTC (rev 37045)
@@ -178,10 +178,21 @@
 For vectors and some plotting commands you can also specify
 '<tt>none</tt>' or '<tt>R:G:B</tt>' (e.g '<tt>255:0:0</tt>').
 </DD>
+
+<DT><B>yes|no</B>
+<DD>For options that take a yes or no answer, you can simply use the
+letters "y" or "n", or type out the full words "Yes" or "No" if you
+prefer. It is not case-sensitive. Typically the option with have a
+default answer and you only need to specify one if you wish to
+override it.
+</DD>
+
+
 </DL>
 <P>
 <BR>
 
+
 <h3>Command usage</h3>
 
 <a name="border"></a>
@@ -219,7 +230,7 @@
 <a name="colortable"></a>
 <H2>colortable</H2>
 
-Prints the color table for the raster map layer anywhere on the page.
+Prints the color table legend for the raster map layer anywhere on the page.
 <PRE>
 USAGE:	<B>colortable</B> [y|n]
 	<B>where</B> x y
@@ -233,53 +244,81 @@
 	<B>color</B> text color
 	<B>nodata</B> [Y|n]
 	<B>tickbar</B> [y|N]
+	<B>discrete</B> [y|N]
 	<B>end</B>
 </PRE>
-The color table will display the colors for each raster map layer
-category value and the category label.
-If <B>raster</B> is omitted, the colortable defaults to a previously
+
+For a categorical (CELL) map the color table will create a legend displaying
+the colors for each of a raster map's category values along with its
+associated category label. For a floating point (FCELL or DCELL) map a
+continuous gradient legend will be created.
+<P>
+If <B>raster</B> is omitted, the colortable defaults to the previously
 registered raster layer.
-The legend's <B>range</B> can be adjusted for floating point rasters, but if 
-set beyond the extent of the map's range be sure that you have set up color 
-rules with <em>r.colors</em> which cover this range.
+
 The default location for the colortable is immediately below any other
 map legend information, starting at the left margin.
 The default text color is black.
 
 Omitting the <B>colortable</B> instruction would result in
-no color table. For floating point legends <B>width</B> is width of color
-band only. <B>height</B> is used only for floating point legend.
-Adding the <B>nodata n</B> instruction will prevent the "no data" box 
-from being drawn (category based legends only).
+no color table.
+<P>
+If the colortable is turned off with a &quot;<tt>colortable&nbsp;N</tt>&quot;
+instruction the <B>end</B> command should not be given as the  
+main command will be treated as a single line instruction.
+<P>
+See also the <a href="#vlegend">vlegend</a> command for creating vector map
+legends.
 
-Adding the <B>tickbar y</B> instruction will change the tick mark style
-so that ticks are drawn across the color table instead of protruding out 
-to the right (floating point legends only).
+<h4>Categorical (CELL) Maps</h4>
 
-If the map has been given a data units label with r.support then this
-label will be displayed.
-<!-- bonus prize for code explorers: you can switch the label placement by
-    editing the label_posn variable in ps.map/ps_fclrtbl.c -->
+Adding the <B>nodata N</B> instruction will prevent the "no data" box 
+from being drawn (category based legends only). If you have manually
+added a "no data" label to the cats/ file it will be shown regardless.
 <P> 
 <B>Note</B>:  Be careful about asking for color tables for integer
 raster map layers which have many categories, such as elevation.
 This could result in the printing of an extremely long color table!
+In this situation it is useful to use <em>r.mapcalc</em> to convert the
+map to a floating point (FCELL) map to take advantage of the continuous
+color gradient legend.
 <P>
-Another issue is that the color table only includes categories which
+Be aware that the color table only includes categories which
 have a label. If there are only a few categories, you can use
-r.support to manually add labels. If there are too many categories to
-do this by hand, you can supply a label rules file to the r.category
+<em>r.support</em> to manually add labels. If there are too many categories to
+do this by hand, you can supply a label rules file to the <em>r.category</em>
 module.
-<P>
-If the colortable is turned off with a &quot;<tt>colortable&nbsp;n</tt>&quot;
-instruction the <B>end</B> command should not be given as the  
-main command will be treated as a single line instruction.
 
+<h4>Floating point (FCELL and DCELL) Maps</h4>
+
+The legend's <B>range</B> can be adjusted for floating point rasters, but if
+set beyond the extent of the map's range be sure that you have set up color 
+rules with <em>r.colors</em> which cover this range.
+
+If the map has been given a data-units label with <em>r.support</em>
+then this label will be displayed.
+<!-- bonus prize for code explorers: you can switch the label placement by
+    editing the label_posn variable in ps.map/ps_fclrtbl.c -->
+
+For floating point legends <B>width</B> is width of color
+band only. <B>height</B> is used only for floating point legend.
+
+Adding the <B>tickbar Y</B> instruction will change the tick mark style
+so that ticks are drawn across the color table instead of protruding out 
+to the right (floating point legends only).
+
+Adding the <B>discrete Y</B> instruction will command the program to treat
+the map as a categorical map. In this way the legend can be created with
+discrete range bands instead of a continuous gradient. You must use the
+<em>r.category</em> or <em>r.support</em> module to set up the range labels
+first.
+
+<BR>
 <P>
 This example would print a color table immediately below any other map legend
 information, starting at the left margin, with 4 columns:
 <PRE>
-EXAMPLE:	
+EXAMPLE:
 	<B>colortable</B> y
         <B>cols</B> 4
         <B>width</B> 4
@@ -1497,6 +1536,9 @@
 <a href="#rectangle">rectangle</a>, <a href="#point">point</a>, and 
 <a href="#text">text</a> instructions.
 <P>
+See also the <a href="#colortable">colortable</a> command for creating
+raster map legends.
+<P>
 This example prints the vector legend
 immediately below the map and starting 4.5 inches from the left edge
 of the page, using a 12/72 inch Helvetica font.

Modified: grass/branches/develbranch_6/ps/ps.map/ps_clrtbl.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/ps_clrtbl.c	2009-05-08 05:57:44 UTC (rev 37044)
+++ grass/branches/develbranch_6/ps/ps.map/ps_clrtbl.c	2009-05-08 06:16:03 UTC (rev 37045)
@@ -44,10 +44,10 @@
     num_cats = G_number_of_raster_cats(&PS.cats);
     G_debug(3, "clrtbl: %d categories", num_cats);
     if (!num_cats) {
-	G_warning(_("Your cats/ file is invalid. A cats/ file with "
-		    "categories and labels is required for 'colortable' when using "
-		    "CELL rasters. No colortable will be assigned to this output "
-		    "postscript file."));
+	G_warning(_("Your cats/ file is invalid. A cats/ file with categories "
+		    "and labels is required for 'colortable' when using "
+		    "categorical legends; see the r.category help page. "
+		    "Colortable creation has been skipped."));
 	return 1;
     }
 

Modified: grass/branches/develbranch_6/ps/ps.map/ps_fclrtbl.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/ps_fclrtbl.c	2009-05-08 05:57:44 UTC (rev 37044)
+++ grass/branches/develbranch_6/ps/ps.map/ps_fclrtbl.c	2009-05-08 06:16:03 UTC (rev 37045)
@@ -267,8 +267,8 @@
 	/* select label position */
 	label_posn = 3;
 	/*  1 2
-	       3
-	     5 4 */
+	      3
+	    5 4 */
 	switch (label_posn) {
 	case 1:
 	    /* above the tick numbers */

Modified: grass/branches/develbranch_6/ps/ps.map/ps_map.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/ps_map.c	2009-05-08 05:57:44 UTC (rev 37044)
+++ grass/branches/develbranch_6/ps/ps.map/ps_map.c	2009-05-08 06:16:03 UTC (rev 37045)
@@ -145,7 +145,7 @@
 
     /* do the colortable, if requested */
     if (PS.do_colortable) {
-	if (G_raster_map_is_fp(ct.name, ct.mapset))
+	if (G_raster_map_is_fp(ct.name, ct.mapset) && ct.discrete == FALSE)
 	    PS_fcolortable();
 	else
 	    PS_colortable();

Modified: grass/branches/develbranch_6/ps/ps.map/r_colortable.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/r_colortable.c	2009-05-08 05:57:44 UTC (rev 37044)
+++ grass/branches/develbranch_6/ps/ps.map/r_colortable.c	2009-05-08 06:16:03 UTC (rev 37045)
@@ -22,7 +22,9 @@
     "fontsize   fontsize",
     "color      color",
     "nodata     Y|n",
-    "tickbar    y|N" ""
+    "tickbar    y|N"
+    "discrete   y|N"
+    ""
 };
 
 int read_colortable(void)
@@ -30,7 +32,7 @@
     char buf[1024];
     char *key, *data;
     char name[GNAME_MAX], mapset[GMAPSET_MAX];
-    int color, fontsize, cols, nodata, tickbar;
+    int color, fontsize, cols, nodata, tickbar, discrete;
     double w, h, x, y;
     int range_override;
     double min, max, tmpD;
@@ -40,8 +42,9 @@
     color = BLACK;
     cols = 1;
     h = w = x = y = 0.0;
-    ct.nodata = 1;
-    ct.tickbar = 0;
+    ct.nodata = TRUE;
+    ct.tickbar = FALSE;
+    ct.discrete = FALSE;
     range_override = FALSE;
 
     while (input(2, buf, help)) {
@@ -138,6 +141,12 @@
 	    continue;
 	}
 
+	if (KEY("discrete")) {
+	    discrete = yesno(key, data);
+	    ct.discrete = discrete;
+	    continue;
+	}
+
 	error(key, data, "illegal colortabe sub-request");
     }
     ct.x = x;



More information about the grass-commit mailing list