[GRASS-SVN] r37047 - grass/branches/releasebranch_6_4/ps/ps.map

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 8 03:31:06 EDT 2009


Author: hamish
Date: 2009-05-08 03:31:05 -0400 (Fri, 08 May 2009)
New Revision: 37047

Modified:
   grass/branches/releasebranch_6_4/ps/ps.map/colortable.h
   grass/branches/releasebranch_6_4/ps/ps.map/description.html
   grass/branches/releasebranch_6_4/ps/ps.map/ps_clrtbl.c
   grass/branches/releasebranch_6_4/ps/ps.map/ps_fclrtbl.c
   grass/branches/releasebranch_6_4/ps/ps.map/ps_map.c
   grass/branches/releasebranch_6_4/ps/ps.map/r_colortable.c
Log:
backport legend type control from devbr6

Modified: grass/branches/releasebranch_6_4/ps/ps.map/colortable.h
===================================================================
--- grass/branches/releasebranch_6_4/ps/ps.map/colortable.h	2009-05-08 06:35:43 UTC (rev 37046)
+++ grass/branches/releasebranch_6_4/ps/ps.map/colortable.h	2009-05-08 07:31:05 UTC (rev 37047)
@@ -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;	/* force discrete bands or continuous gradient */
     int range_override;
 };
 

Modified: grass/branches/releasebranch_6_4/ps/ps.map/description.html
===================================================================
--- grass/branches/releasebranch_6_4/ps/ps.map/description.html	2009-05-08 06:35:43 UTC (rev 37046)
+++ grass/branches/releasebranch_6_4/ps/ps.map/description.html	2009-05-08 07:31:05 UTC (rev 37047)
@@ -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,82 @@
 	<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).
 
-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 -->
+<h4>Categorical (CELL) Maps</h4>
+
+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 the <B>discrete N</B> instruction
+to force a 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 +1537,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/releasebranch_6_4/ps/ps.map/ps_clrtbl.c
===================================================================
--- grass/branches/releasebranch_6_4/ps/ps.map/ps_clrtbl.c	2009-05-08 06:35:43 UTC (rev 37046)
+++ grass/branches/releasebranch_6_4/ps/ps.map/ps_clrtbl.c	2009-05-08 07:31:05 UTC (rev 37047)
@@ -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/releasebranch_6_4/ps/ps.map/ps_fclrtbl.c
===================================================================
--- grass/branches/releasebranch_6_4/ps/ps.map/ps_fclrtbl.c	2009-05-08 06:35:43 UTC (rev 37046)
+++ grass/branches/releasebranch_6_4/ps/ps.map/ps_fclrtbl.c	2009-05-08 07:31:05 UTC (rev 37047)
@@ -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/releasebranch_6_4/ps/ps.map/ps_map.c
===================================================================
--- grass/branches/releasebranch_6_4/ps/ps.map/ps_map.c	2009-05-08 06:35:43 UTC (rev 37046)
+++ grass/branches/releasebranch_6_4/ps/ps.map/ps_map.c	2009-05-08 07:31:05 UTC (rev 37047)
@@ -145,10 +145,10 @@
 
     /* do the colortable, if requested */
     if (PS.do_colortable) {
-	if (G_raster_map_is_fp(ct.name, ct.mapset))
+	if (ct.discrete == TRUE)
+	    PS_colortable();
+	else
 	    PS_fcolortable();
-	else
-	    PS_colortable();
     }
 
     /* do comments, if any */

Modified: grass/branches/releasebranch_6_4/ps/ps.map/r_colortable.c
===================================================================
--- grass/branches/releasebranch_6_4/ps/ps.map/r_colortable.c	2009-05-08 06:35:43 UTC (rev 37046)
+++ grass/branches/releasebranch_6_4/ps/ps.map/r_colortable.c	2009-05-08 07:31:05 UTC (rev 37047)
@@ -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 = -1;	    /* default: TRUE for CELL map, FALSE for FP maps */
     range_override = FALSE;
 
     while (input(2, buf, help)) {
@@ -138,8 +141,15 @@
 	    continue;
 	}
 
+	if (KEY("discrete")) {
+	    discrete = yesno(key, data);
+	    ct.discrete = discrete;
+	    continue;
+	}
+
 	error(key, data, "illegal colortabe sub-request");
     }
+
     ct.x = x;
     ct.y = y;
     if (fontsize)
@@ -156,6 +166,14 @@
 	}
     }
 
+    /* set default if legend type was not specified */
+    if (ct.discrete == -1) {
+	if (G_raster_map_is_fp(ct.name, ct.mapset))
+	    ct.discrete = FALSE;
+	else
+	    ct.discrete = TRUE;
+    }
+
     ct.min = min;
     ct.max = max;
     ct.range_override = range_override;



More information about the grass-commit mailing list