[GRASS-SVN] r33370 - grass/trunk/ps/ps.map
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Sep 10 06:21:06 EDT 2008
Author: hamish
Date: 2008-09-10 06:21:06 -0400 (Wed, 10 Sep 2008)
New Revision: 33370
Added:
grass/trunk/ps/ps.map/distance.h
Modified:
grass/trunk/ps/ps.map/decorate.h
grass/trunk/ps/ps.map/do_scalebar.c
grass/trunk/ps/ps.map/get_scalebar.c
grass/trunk/ps/ps.map/map_setup.c
grass/trunk/ps/ps.map/ps.map.html
grass/trunk/ps/ps.map/scale.c
Log:
* add scalebar unit labels
* move distance consts to their own header file
* make METERS_TO_INCHES exact
* update wiki URL
(merge from devbr6, wish #64)
Modified: grass/trunk/ps/ps.map/decorate.h
===================================================================
--- grass/trunk/ps/ps.map/decorate.h 2008-09-10 10:18:47 UTC (rev 33369)
+++ grass/trunk/ps/ps.map/decorate.h 2008-09-10 10:21:06 UTC (rev 33370)
@@ -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;
};
extern struct scalebar sb;
Copied: grass/trunk/ps/ps.map/distance.h (from rev 33368, grass/branches/develbranch_6/ps/ps.map/distance.h)
===================================================================
--- grass/trunk/ps/ps.map/distance.h (rev 0)
+++ grass/trunk/ps/ps.map/distance.h 2008-09-10 10:21:06 UTC (rev 33370)
@@ -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/trunk/ps/ps.map/do_scalebar.c
===================================================================
--- grass/trunk/ps/ps.map/do_scalebar.c 2008-09-10 10:18:47 UTC (rev 33369)
+++ grass/trunk/ps/ps.map/do_scalebar.c 2008-09-10 10:21:06 UTC (rev 33370)
@@ -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/trunk/ps/ps.map/get_scalebar.c
===================================================================
--- grass/trunk/ps/ps.map/get_scalebar.c 2008-09-10 10:18:47 UTC (rev 33369)
+++ grass/trunk/ps/ps.map/get_scalebar.c 2008-09-10 10:21:06 UTC (rev 33370)
@@ -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/trunk/ps/ps.map/map_setup.c
===================================================================
--- grass/trunk/ps/ps.map/map_setup.c 2008-09-10 10:18:47 UTC (rev 33369)
+++ grass/trunk/ps/ps.map/map_setup.c 2008-09-10 10:21:06 UTC (rev 33370)
@@ -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/trunk/ps/ps.map/ps.map.html
===================================================================
--- grass/trunk/ps/ps.map/ps.map.html 2008-09-10 10:18:47 UTC (rev 33369)
+++ grass/trunk/ps/ps.map/ps.map.html 2008-09-10 10:21:06 UTC (rev 33370)
@@ -154,7 +154,8 @@
</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 @@
<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 @@
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 @@
<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 @@
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:
Modified: grass/trunk/ps/ps.map/scale.c
===================================================================
--- grass/trunk/ps/ps.map/scale.c 2008-09-10 10:18:47 UTC (rev 33369)
+++ grass/trunk/ps/ps.map/scale.c 2008-09-10 10:21:06 UTC (rev 33370)
@@ -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