Browse Source

* add scalebar unit labels
* move distance consts to their own header file
* make METERS_TO_INCHES exact
* update wiki URL
(merge from devbr6, wish https://trac.osgeo.org/grass/ticket/64)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33370 15284696-431f-4ddb-bdfa-cd5b030d7da7

Hamish Bowman 16 years ago
parent
commit
13dc225615
7 changed files with 117 additions and 14 deletions
  1. 10 0
      ps/ps.map/decorate.h
  2. 16 0
      ps/ps.map/distance.h
  3. 40 3
      ps/ps.map/do_scalebar.c
  4. 32 0
      ps/ps.map/get_scalebar.c
  5. 1 1
      ps/ps.map/map_setup.c
  6. 17 8
      ps/ps.map/ps.map.html
  7. 1 2
      ps/ps.map/scale.c

+ 10 - 0
ps/ps.map/decorate.h

@@ -4,6 +4,15 @@
 
 #include <stdio.h>
 
+
+/* units options */
+#define SB_UNITS_AUTO	0
+#define SB_UNITS_METERS	1
+#define SB_UNITS_KM	2
+#define SB_UNITS_FEET	3
+#define SB_UNITS_MILES	4
+#define SB_UNITS_NMILES	5
+
 struct scalebar
 {
     char type[50];
@@ -15,6 +24,7 @@ struct scalebar
     double width;
     int fontsize;
     int color, bgcolor;
+    int units;
 };
 
 extern struct scalebar sb;

+ 16 - 0
ps/ps.map/distance.h

@@ -0,0 +1,16 @@
+/* some useful conversion factors */
+
+#ifndef __DISTANCE_H__
+#define __DISTANCE_H__
+
+
+#define METERS_TO_INCHES ((double)1/0.0254)
+#define MILES_TO_INCHES  ((double)5280*12)
+
+#define FEET_TO_METERS 0.3048
+#define MILES_TO_METERS 1609.344
+#define NAUT_MILES_TO_METERS 1852.0
+#define KILOMETERS_TO_METERS 1000.0
+
+
+#endif /* __DISTANCE_H__ */

+ 40 - 3
ps/ps.map/do_scalebar.c

@@ -7,8 +7,8 @@
 #include "ps_info.h"
 #include "decorate.h"
 #include "local_proto.h"
+#include "distance.h"
 
-#define METERS_TO_INCHES ((double)39.37)
 #define LEFT 0
 #define RIGHT 1
 #define LOWER 0
@@ -28,12 +28,24 @@ int do_scalebar(void)
 
     /* get scale size */
     scale_size =
-	METERS_TO_INCHES * distance(PS.w.east,
-				    PS.w.west) / scale(PS.scaletext);
+	METERS_TO_INCHES * distance(PS.w.east, PS.w.west) / scale(PS.scaletext);
 
     /* convert scale size to map inches */
     length = (sb.length / scale_size) *
 	G_database_units_to_meters_factor() * METERS_TO_INCHES;
+
+    /* if(sb.units == SB_UNITS_AUTO) { do nothing } */
+    if(sb.units == SB_UNITS_METERS)
+	    length /= G_database_units_to_meters_factor();
+    else if(sb.units == SB_UNITS_KM)
+	    length *= KILOMETERS_TO_METERS / G_database_units_to_meters_factor();
+    else if(sb.units == SB_UNITS_FEET)
+	    length *= FEET_TO_METERS / G_database_units_to_meters_factor();
+    else if(sb.units == SB_UNITS_MILES)
+	    length *= MILES_TO_METERS / G_database_units_to_meters_factor();
+    else if(sb.units == SB_UNITS_NMILES)
+	    length *= NAUT_MILES_TO_METERS / G_database_units_to_meters_factor();
+
     width = sb.height;
     seg = sb.segment;
     j = 0;
@@ -178,6 +190,31 @@ int do_scalebar(void)
     }
 
 
+    /* draw units label */
+    if (sb.units == SB_UNITS_AUTO)
+	strcpy(num, G_database_unit_name(TRUE));
+    else if(sb.units == SB_UNITS_METERS)
+	strcpy(num, "meters");
+    else if(sb.units == SB_UNITS_KM)
+	strcpy(num, "kilometers");
+    else if(sb.units == SB_UNITS_FEET)
+	strcpy(num, "feet");
+    else if(sb.units == SB_UNITS_MILES)
+	strcpy(num, "miles");
+    else if(sb.units == SB_UNITS_NMILES)
+	strcpy(num, "nautical miles");
+    
+    text_box_path(72.0 * (x + length/2), 72.0 * (PS.page_height - (sb.y + 0.075)),
+	CENTER, UPPER, num, sb.fontsize, 0);
+
+    if (sb.bgcolor) {
+	set_rgb_color(WHITE);
+	fprintf(PS.fp, "F ");
+    }
+    set_rgb_color(BLACK);
+    fprintf(PS.fp, "TIB\n");
+
+
     return 0;
 }
 

+ 32 - 0
ps/ps.map/get_scalebar.c

@@ -14,6 +14,7 @@
 static char *help[] = {
     "where      x y",
     "length	length",
+    "units	auto|meters|kilometers|feet|miles|nautmiles",
     "height	height",
     "segment	no_segemnts",
     "numbers	no_labels",
@@ -38,6 +39,7 @@ int read_scalebar(void)
     sb.x = PS.page_width / 2.;
     sb.y = 2.;
     sb.bgcolor = 1;		/* default is "on" [white|none] (TODO: multi-color) */
+    sb.units = SB_UNITS_AUTO;   /* default to automatic based on value in PROJ_UNITS */
 
 
     while (input(2, buf, help)) {
@@ -68,6 +70,36 @@ int read_scalebar(void)
 		continue;
 	}
 
+	if (KEY("units")) {
+	    G_strip(data);
+	    if (strcmp(data, "auto") == 0) {
+		sb.units = SB_UNITS_AUTO;
+		continue;
+	    }
+	    else if (strcmp(data, "meters") == 0) {
+		sb.units = SB_UNITS_METERS;
+		continue;
+	    }
+	    else if (strcmp(data, "kilometers") == 0 || strcmp(data, "km") == 0) {
+		sb.units = SB_UNITS_KM;
+		continue;
+	    }
+	    else if (strcmp(data, "feet") == 0) {
+		sb.units = SB_UNITS_FEET;
+		continue;
+	    }
+	    else if (strcmp(data, "miles") == 0) {
+		sb.units = SB_UNITS_MILES;
+		continue;
+	    }
+	    else if (strcmp(data, "nautmiles") == 0 || strcmp(data, "nm") == 0) {
+		sb.units = SB_UNITS_NMILES;
+		continue;
+	    }
+	    else
+		error(key, data, "illegal units request");
+	}
+
 	if (KEY("segment")) {
 	    if (sscanf(data, "%d", &sb.segment) != 1 || sb.segment <= 0) {
 		error(key, data, "illegal segment request");

+ 1 - 1
ps/ps.map/map_setup.c

@@ -8,8 +8,8 @@
 #include "ps_info.h"
 #include "group.h"
 #include "local_proto.h"
+#include "distance.h"
 
-#define METERS_TO_INCHES ((double)39.37)
 
 int map_setup(void)
 {

+ 17 - 8
ps/ps.map/ps.map.html

@@ -154,7 +154,8 @@ The default is 10.
 </DD>
 
 
-<DT><a name="NAMED_COLORS"></a><B>color</B> <EM>name</EM>
+<a name="NAMED_COLORS"></a>
+<DT><B>color</B> <EM>name</EM>
 
 <DD>The following colors names are accepted by <EM>ps.map</EM>:
 <tt>
@@ -1024,9 +1025,10 @@ Draws a scalebar on the map.
 <PRE>
 USAGE:	<B>scalebar</B> [f|s]
 	<B>where</B> x y
-	<B>length</B> scale length
-	<B>height</B> scale height
-	<B>segment</B> no. segments
+	<B>length</B> overall distance in map units
+	<B>units</B> [auto|meters|kilometers|feet|miles|nautmiles]
+	<B>height</B> scale height in inches
+	<B>segment</B> number of segments
 	<B>numbers</B> #
 	<B>fontsize</B> font size
 	<B>background</B> [Y|n]
@@ -1035,11 +1037,16 @@ USAGE:	<B>scalebar</B> [f|s]
 Draw one of two types of scale bar.
 Fancy (f) draws alternating black and white scale boxes.
 Simple (s) draws a plain line scale. The default type is fancy.
+
 The subsection instructions allow the user to set <B>where</B> the scalebar
 is placed, the <B>length</B> of the scalebar (in geographic coordinate
-system units), the <B>height</B> of the scalebar in inches, and the number of
+system units, or those given by <B>units</B>),
+<!-- bonus prize for code explorers: you can use km and nm abbreviations
+     for kilometers and nautmiles units -->
+the <B>height</B> of the scalebar in inches, and the number of
 <B>segments</B> (or tics for simple). The <B>number</B> of annotations
 numbers every n-th segment.
+
 The <B>background</B> command can turn off the background box for the text.
 <P>
 The scalebar <B>length</B> is the only required argument. The defaults are a
@@ -1049,8 +1056,10 @@ halfway across.
 <P>
 NOTE: The scalebar is centered on the location given.
 <P>
-This example draws a simple scalebar 1000 meters (for a metered database, like UTM) long,
-with tics every 200 meters, labeled every second tic. The scalebar is drawn 5 inches from the top and 4 inches from the left and is 0.25 inches high.
+This example draws a simple scalebar 1000 meters (for a metered database,
+like UTM) long, with tics every 200 meters, labeled every second tic.
+The scalebar is drawn 5 inches from the top and 4 inches from the left
+and is 0.25 inches high.
 <PRE>
 EXAMPLE:
 	<B>scalebar</B> s
@@ -1252,7 +1261,7 @@ in the pattern file.
 Pattern may be scaled with the <b>scale</b> command. Several standard hatching
 patterns are provided in <tt>$GISBASE/etc/paint/patterns/</tt>.
 Demonstrative images can be found on the
-<a href="http://grass.gdf-hannover.de/wiki/AreaFillPatterns">GRASS Wiki site</a>.
+<a href="http://grass.osgeo.org/wiki/AreaFillPatterns">GRASS Wiki site</a>.
 
 You can also create your own custom pattern files in a text editor. 
 Example of pattern file:

+ 1 - 2
ps/ps.map/scale.c

@@ -11,9 +11,8 @@
 #include <grass/glocale.h>
 #include "local_proto.h"
 #include "ps_info.h"
+#include "distance.h"
 
-#define METERS_TO_INCHES ((double)39.37)
-#define MILES_TO_INCHES  ((double)5280*12)
 #define PWIDTH	(PS.page_width-PS.left_marg-PS.right_marg)
 static double do_scale(char *);