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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 10 06:04:17 EDT 2008


Author: hamish
Date: 2008-09-10 06:04:17 -0400 (Wed, 10 Sep 2008)
New Revision: 33368

Added:
   grass/branches/develbranch_6/ps/ps.map/distance.h
Modified:
   grass/branches/develbranch_6/ps/ps.map/decorate.h
   grass/branches/develbranch_6/ps/ps.map/description.html
   grass/branches/develbranch_6/ps/ps.map/do_scalebar.c
   grass/branches/develbranch_6/ps/ps.map/get_scalebar.c
   grass/branches/develbranch_6/ps/ps.map/map_setup.c
   grass/branches/develbranch_6/ps/ps.map/scale.c
Log:
* add scalebar unit labels
* move distance consts to their own header file
* make METERS_TO_INCHES exact


Modified: grass/branches/develbranch_6/ps/ps.map/decorate.h
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/decorate.h	2008-09-10 08:59:00 UTC (rev 33367)
+++ grass/branches/develbranch_6/ps/ps.map/decorate.h	2008-09-10 10:04:17 UTC (rev 33368)
@@ -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 @@
     double width;
     int fontsize;
     int color, bgcolor;
+    int units;
 };
 
 #ifdef MAIN

Modified: grass/branches/develbranch_6/ps/ps.map/description.html
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/description.html	2008-09-10 08:59:00 UTC (rev 33367)
+++ grass/branches/develbranch_6/ps/ps.map/description.html	2008-09-10 10:04:17 UTC (rev 33368)
@@ -1025,9 +1025,10 @@
 <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]
@@ -1036,11 +1037,16 @@
 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
@@ -1050,8 +1056,10 @@
 <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

Added: grass/branches/develbranch_6/ps/ps.map/distance.h
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/distance.h	                        (rev 0)
+++ grass/branches/develbranch_6/ps/ps.map/distance.h	2008-09-10 10:04:17 UTC (rev 33368)
@@ -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__ */

Modified: grass/branches/develbranch_6/ps/ps.map/do_scalebar.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/do_scalebar.c	2008-09-10 08:59:00 UTC (rev 33367)
+++ grass/branches/develbranch_6/ps/ps.map/do_scalebar.c	2008-09-10 10:04:17 UTC (rev 33368)
@@ -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 @@
 
     /* 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 @@
     }
 
 
+    /* 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;
 }
 

Modified: grass/branches/develbranch_6/ps/ps.map/get_scalebar.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/get_scalebar.c	2008-09-10 08:59:00 UTC (rev 33367)
+++ grass/branches/develbranch_6/ps/ps.map/get_scalebar.c	2008-09-10 10:04:17 UTC (rev 33368)
@@ -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 @@
     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 @@
 		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");

Modified: grass/branches/develbranch_6/ps/ps.map/map_setup.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/map_setup.c	2008-09-10 08:59:00 UTC (rev 33367)
+++ grass/branches/develbranch_6/ps/ps.map/map_setup.c	2008-09-10 10:04:17 UTC (rev 33368)
@@ -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)
 {

Modified: grass/branches/develbranch_6/ps/ps.map/scale.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/scale.c	2008-09-10 08:59:00 UTC (rev 33367)
+++ grass/branches/develbranch_6/ps/ps.map/scale.c	2008-09-10 10:04:17 UTC (rev 33368)
@@ -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 *);
 



More information about the grass-commit mailing list