[GRASS-SVN] r57699 - grass/branches/develbranch_6/display/d.grid

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Sep 16 02:37:26 PDT 2013


Author: hamish
Date: 2013-09-16 02:37:26 -0700 (Mon, 16 Sep 2013)
New Revision: 57699

Modified:
   grass/branches/develbranch_6/display/d.grid/description.html
   grass/branches/develbranch_6/display/d.grid/local_proto.h
   grass/branches/develbranch_6/display/d.grid/main.c
   grass/branches/develbranch_6/display/d.grid/plot.c
   grass/branches/develbranch_6/display/d.grid/plotborder.c
Log:
add direction= option to allow rendering only lines of latitude or longitude (refs#1372)

Modified: grass/branches/develbranch_6/display/d.grid/description.html
===================================================================
--- grass/branches/develbranch_6/display/d.grid/description.html	2013-09-16 01:13:00 UTC (rev 57698)
+++ grass/branches/develbranch_6/display/d.grid/description.html	2013-09-16 09:37:26 UTC (rev 57699)
@@ -43,13 +43,21 @@
 <p>
 Colors may be standard named GRASS colors (red, green, aqua, etc.) or
 a numerical R:G:B triplet, where component values range from 0-255.<br>
+
 <p>
 The grid drawing may be turned off by using the <em>-n</em> flag.<br>
 The border drawing may be turned off by using the <em>-b</em> flag.<br>
 The coordinate text may be turned off by using the <em>-t</em> flag.<br>
 
+<p>
+To draw grid lines at different intervals, e.g. at high latitudes, you
+can run the module twice, once with <b>direction</b>=<i>east-west</i>
+at one interval <b>size</b>, and again with
+<b>direction</b>=<i>north-south</i> at another interval <b>size</b>.
 
+
 <h2>EXAMPLES</h2>
+
 To draw a red geographic grid with 30 minute grid spacing run 
 either of the following:
 <PRE>
@@ -65,6 +73,7 @@
 </PRE>
 <br>
 
+
 <h2>SEE ALSO</h2>
 
 <em><a href="d.barscale.html">d.barscale</a></em><br>
@@ -76,7 +85,6 @@
 <em><a href="d.rast.html">d.rast</a></em><br>
 
 
-
 <h2>AUTHORS</h2>
 
 James Westervelt, U.S. Army Construction Engineering Research Laboratory<br>
@@ -84,4 +92,5 @@
 Border support: Markus Neteler<br>
 Text and RGB support: Hamish Bowman<br>
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>

Modified: grass/branches/develbranch_6/display/d.grid/local_proto.h
===================================================================
--- grass/branches/develbranch_6/display/d.grid/local_proto.h	2013-09-16 01:13:00 UTC (rev 57698)
+++ grass/branches/develbranch_6/display/d.grid/local_proto.h	2013-09-16 09:37:26 UTC (rev 57699)
@@ -1,9 +1,13 @@
 #include <grass/gprojects.h>
 
+#define DIRN_BOTH 0
+#define DIRN_LAT  1
+#define DIRN_LON  2
+
 /* plot.c */
-int plot_grid(double, double, double, int, int, int, int, int, double);
+int plot_grid(double, double, double, int, int, int, int, int, double, int);
 int plot_geogrid(double, struct pj_info, struct pj_info, int, int, int, int,
-		 int, double);
+		 int, double, int);
 void init_proj(struct pj_info *, struct pj_info *, int);
 void get_ll_bounds(double *, double *, double *, double *, struct Cell_head,
 		   struct pj_info, struct pj_info);
@@ -12,7 +16,7 @@
 float get_heading(double, double);
 
 /* plotborder.c */
-int plot_border(double, double, double);
+int plot_border(double, double, double, int);
 
 #define MARK_GRID     0
 #define MARK_CROSS    1

Modified: grass/branches/develbranch_6/display/d.grid/main.c
===================================================================
--- grass/branches/develbranch_6/display/d.grid/main.c	2013-09-16 01:13:00 UTC (rev 57698)
+++ grass/branches/develbranch_6/display/d.grid/main.c	2013-09-16 09:37:26 UTC (rev 57699)
@@ -36,9 +36,10 @@
     int colort = 0;
     double size = 0., gsize = 0.;	/* initialize to zero */
     double east, north;
-    int do_text, fontsize, mark_type, line_width;
+    int do_text, fontsize, mark_type, line_width, dirn;
     struct GModule *module;
-    struct Option *opt1, *opt2, *opt3, *opt4, *fsize, *tcolor, *lwidth;
+    struct Option *opt1, *opt2, *opt3, *opt4, *fsize, *tcolor, *lwidth,
+	*direction;
     struct Flag *noborder, *notext, *geogrid, *nogrid, *wgs84, *cross,
 	*fiducial, *dot;
     struct pj_info info_in;	/* Proj structures */
@@ -70,6 +71,16 @@
     opt3->multiple = NO;
     opt3->description = _("Lines of the grid pass through this coordinate");
 
+    direction = G_define_option();
+    direction->key = "direction";
+    direction->type = TYPE_STRING;
+    direction->required = NO;
+    direction->answer = "both";
+    direction->options = "both,east-west,north-south";
+    direction->description =
+	_("Draw only east-west lines, north-south lines, or both ");
+    direction->guisection = _("Disable");
+
     lwidth = G_define_option();
     lwidth->key = "width";
     lwidth->type = TYPE_DOUBLE;
@@ -177,6 +188,15 @@
     if (dot->answer)
 	mark_type = MARK_DOT;
 
+    if (G_strcasecmp(direction->answer, "both") == 0)
+        dirn = DIRN_BOTH;
+    else if (G_strcasecmp(direction->answer, "east-west") == 0)
+        dirn = DIRN_LAT;
+    else if (G_strcasecmp(direction->answer, "north-south") == 0)
+        dirn = DIRN_LON;
+    else
+        G_fatal_error("Invalid direction: %s", direction->answer);
+
     /* get grid size */
     if (geogrid->answer) {
 	if (!G_scan_resolution(opt2->answer, &gsize, PROJECTION_LL) ||
@@ -222,12 +242,12 @@
 	    /* initialzie proj stuff */
 	    init_proj(&info_in, &info_out, wgs84->answer);
 	    plot_geogrid(gsize, info_in, info_out, do_text, colorg, colort,
-			 fontsize, mark_type, line_width);
+			 fontsize, mark_type, line_width, dirn);
 	}
 	else {
 	    /* Do the grid plotting */
 	    plot_grid(size, east, north, do_text, colorg, colort, fontsize,
-		      mark_type, line_width);
+		      mark_type, line_width, dirn);
 	}
     }
 
@@ -237,7 +257,7 @@
 	D_raster_use_color(colorb);
 
 	/* Do the border plotting */
-	plot_border(size, east, north);
+	plot_border(size, east, north, dirn);
     }
 
     D_add_to_list(G_recreate_command());

Modified: grass/branches/develbranch_6/display/d.grid/plot.c
===================================================================
--- grass/branches/develbranch_6/display/d.grid/plot.c	2013-09-16 01:13:00 UTC (rev 57698)
+++ grass/branches/develbranch_6/display/d.grid/plot.c	2013-09-16 09:37:26 UTC (rev 57699)
@@ -12,7 +12,7 @@
 
 int plot_grid(double grid_size, double east, double north, int do_text,
 	      int gcolor, int tcolor, int fontsize, int mark_type,
-	      double line_width)
+	      double line_width, int direction)
 {
     double x, y, y0;
     double e1, e2;
@@ -38,38 +38,39 @@
     else
 	x = east - ceil((east - window.west) / grid_size) * grid_size;
 
-    while (x <= window.east) {
+    if (direction != DIRN_LAT) {
+	while (x <= window.east) {
 
-	if (mark_type == MARK_GRID) {
-	    D_raster_use_color(gcolor);
-	    if (line_width)
-		D_line_width(line_width);
-	    G_plot_line(x, window.north, x, window.south);
-	    D_line_width(0);	/* reset so text doesn't use it */
-	}
+	    if (mark_type == MARK_GRID) {
+		D_raster_use_color(gcolor);
+		if (line_width)
+		    D_line_width(line_width);
+		G_plot_line(x, window.north, x, window.south);
+		D_line_width(0);    /* reset so text doesn't use it */
+	    }
 
-	if (do_text) {
-	    D_raster_use_color(tcolor);
-	    G_format_easting(x, text, G_projection());
-	    R_text_rotation(270.0);
-	    R_text_size(fontsize, fontsize);
+	    if (do_text) {
+		D_raster_use_color(tcolor);
+		G_format_easting(x, text, G_projection());
+		R_text_rotation(270.0);
+		R_text_size(fontsize, fontsize);
 
-	    /* Positioning -
-	       x: 4 pixels to the right of the grid line, + 0.5 rounding factor.
-	       y: End of text is 7 pixels up from bottom of screen, +.5 rounding.
-	       fontsize*.81 = actual text width FOR DEFAULT FONT (NOT FreeType)
-	     */
-	    R_move_abs((int)(D_u_to_d_col(x) + 4 + .5),
-		       (int)(D_get_d_south() -
-			     (strlen(text) * fontsize * 0.81) - 7 + 0.5));
+		/* Positioning -
+		   x: 4 pixels to the right of the grid line, + 0.5 rounding factor.
+		   y: End of text is 7 pixels up from bottom of screen, +.5 rounding.
+		   fontsize*.81 = actual text width FOR DEFAULT FONT (NOT FreeType)
+		 */
+		R_move_abs((int)(D_u_to_d_col(x) + 4 + .5),
+			   (int)(D_get_d_south() -
+				 (strlen(text) * fontsize * 0.81) - 7 + 0.5));
 
-	    R_text(text);
+		R_text(text);
+	    }
+	    x += grid_size;
 	}
-	x += grid_size;
+	R_text_rotation(0.0);	    /* reset */
     }
-    R_text_rotation(0.0);	/* reset */
 
-
     /* Draw horizontal grids
      *
      * For latlon, must draw in shorter sections
@@ -84,34 +85,36 @@
     else
 	y = north - ceil((north - window.south) / grid_size) * grid_size;
 
-    while (y <= window.north) {
-	if (mark_type == MARK_GRID) {
-	    D_raster_use_color(gcolor);
-	    if (line_width)
-		D_line_width(line_width);
-	    G_plot_line(window.east, y, e1, y);
-	    G_plot_line(e1, y, e2, y);
-	    G_plot_line(e2, y, window.west, y);
-	    D_line_width(0);	/* reset so text doesn't use it */
-	}
+    if (direction != DIRN_LON) {
+	while (y <= window.north) {
+	    if (mark_type == MARK_GRID) {
+		D_raster_use_color(gcolor);
+		if (line_width)
+		    D_line_width(line_width);
+		G_plot_line(window.east, y, e1, y);
+		G_plot_line(e1, y, e2, y);
+		G_plot_line(e2, y, window.west, y);
+		D_line_width(0);    /* reset so text doesn't use it */
+	    }
 
-	if (do_text) {
-	    D_raster_use_color(tcolor);
-	    G_format_northing(y, text, G_projection());
-	    R_text_size(fontsize, fontsize);
+	    if (do_text) {
+		D_raster_use_color(tcolor);
+		G_format_northing(y, text, G_projection());
+		R_text_size(fontsize, fontsize);
 
-	    /* Positioning -
-	       x: End of text is 7 pixels left from right edge of screen, +.5 rounding.
-	       fontsize*.81 = actual text width FOR DEFAULT FONT (NOT FreeType)
-	       y: 4 pixels above each grid line, +.5 rounding.
-	     */
-	    R_move_abs((int)
-		       (D_get_d_east() - (strlen(text) * fontsize * 0.81) -
-			7 + 0.5), (int)(D_u_to_d_row(y) - 4 + .5));
+		/* Positioning -
+		   x: End of text is 7 pixels left from right edge of screen, +.5 rounding.
+		   fontsize*.81 = actual text width FOR DEFAULT FONT (NOT FreeType)
+		   y: 4 pixels above each grid line, +.5 rounding.
+		 */
+		R_move_abs((int)
+			   (D_get_d_east() - (strlen(text) * fontsize * 0.81) -
+			    7 + 0.5), (int)(D_u_to_d_row(y) - 4 + .5));
 
-	    R_text(text);
+		R_text(text);
+	    }
+	    y += grid_size;
 	}
-	y += grid_size;
     }
 
     /* draw marks not grid lines */
@@ -148,7 +151,7 @@
 
 int plot_geogrid(double size, struct pj_info info_in, struct pj_info info_out,
 		 int do_text, int gcolor, int tcolor, int fontsize,
-		 int mark_type, double line_width)
+		 int mark_type, double line_width, int direction)
 {
     double g;
     double e1, e2, n1, n2;
@@ -189,7 +192,7 @@
     e1 = east;
     for (j = 0; g >= south; j++, g -= size) {
 	start_coord = -9999.;
-	if (g == north || g == south)
+	if (g == north || g == south || direction == DIRN_LON)
 	    continue;
 
 	/* Set grid color */
@@ -244,7 +247,7 @@
     for (j = 0; g > west; j++, g -= size) {
 	start_coord = -9999.;
 	extra_y_off = 0.0;
-	if (g == east || g == west)
+	if (g == east || g == west || direction == DIRN_LAT)
 	    continue;
 
 	/* Set grid color */

Modified: grass/branches/develbranch_6/display/d.grid/plotborder.c
===================================================================
--- grass/branches/develbranch_6/display/d.grid/plotborder.c	2013-09-16 01:13:00 UTC (rev 57698)
+++ grass/branches/develbranch_6/display/d.grid/plotborder.c	2013-09-16 09:37:26 UTC (rev 57699)
@@ -1,8 +1,9 @@
 #include <math.h>
 #include <grass/gis.h>
 #include <grass/display.h>
+#include "local_proto.h"
 
-int plot_border(double grid_size, double east, double north)
+int plot_border(double grid_size, double east, double north, int direction)
 {
     double x, y;
     struct Cell_head window;
@@ -41,39 +42,41 @@
     else
 	x = east - ceil((east - window.west) / grid_size) * grid_size;
 
-    while (x <= window.east) {
-	loop = 0;
-	for (i = 0; i <= grid_size; i = i + steps) {
-	    if (loop == 0) {
-		G_plot_line(x + i,
-			    window.south + (window.north -
-					    window.south) / longmark, x + i,
-			    window.south);
-		G_plot_line(x + i, window.north, x + i,
-			    window.north - (window.north -
-					    window.south) / longmark);
+    if (direction != DIRN_LAT) {
+	while (x <= window.east) {
+	    loop = 0;
+	    for (i = 0; i <= grid_size; i = i + steps) {
+		if (loop == 0) {
+		    G_plot_line(x + i,
+				window.south + (window.north -
+						window.south) / longmark, x + i,
+				window.south);
+		    G_plot_line(x + i, window.north, x + i,
+				window.north - (window.north -
+						window.south) / longmark);
+		}
+		if (loop == 5) {
+		    G_plot_line(x + i,
+				window.south + (window.north -
+						window.south) / middlemark, x + i,
+				window.south);
+		    G_plot_line(x + i, window.north, x + i,
+				window.north - (window.north -
+						window.south) / middlemark);
+		}
+		else {
+		    G_plot_line(x + i,
+				window.south + (window.north -
+						window.south) / shortmark, x + i,
+				window.south);
+		    G_plot_line(x + i, window.north, x + i,
+				window.north - (window.north -
+						window.south) / shortmark);
+		}
+		loop++;
 	    }
-	    if (loop == 5) {
-		G_plot_line(x + i,
-			    window.south + (window.north -
-					    window.south) / middlemark, x + i,
-			    window.south);
-		G_plot_line(x + i, window.north, x + i,
-			    window.north - (window.north -
-					    window.south) / middlemark);
-	    }
-	    else {
-		G_plot_line(x + i,
-			    window.south + (window.north -
-					    window.south) / shortmark, x + i,
-			    window.south);
-		G_plot_line(x + i, window.north, x + i,
-			    window.north - (window.north -
-					    window.south) / shortmark);
-	    }
-	    loop++;
+	    x += grid_size;
 	}
-	x += grid_size;
     }
 
     /* Draw horizontal border marks */
@@ -83,36 +86,38 @@
     else
 	y = north - ceil((north - window.south) / grid_size) * grid_size;
 
-    while (y <= window.north) {
-	loop = 0;
-	for (i = 0; i <= grid_size; i = i + steps) {
-	    if (loop == 0) {
-		G_plot_line(window.west, y + i,
-			    window.west + (window.east -
-					   window.west) / longmark, y + i);
-		G_plot_line(window.east -
-			    (window.east - window.west) / longmark, y + i,
-			    window.east, y + i);
+    if (direction != DIRN_LON) {
+	while (y <= window.north) {
+	    loop = 0;
+	    for (i = 0; i <= grid_size; i = i + steps) {
+		if (loop == 0) {
+		    G_plot_line(window.west, y + i,
+				window.west + (window.east -
+					       window.west) / longmark, y + i);
+		    G_plot_line(window.east -
+				(window.east - window.west) / longmark, y + i,
+				window.east, y + i);
+		}
+		if (loop == 5) {
+		    G_plot_line(window.west, y + i,
+				window.west + (window.east -
+					       window.west) / middlemark, y + i);
+		    G_plot_line(window.east -
+				(window.east - window.west) / middlemark, y + i,
+				window.east, y + i);
+		}
+		else {
+		    G_plot_line(window.west, y + i,
+				window.west + (window.east -
+					       window.west) / shortmark, y + i);
+		    G_plot_line(window.east -
+				(window.east - window.west) / shortmark, y + i,
+				window.east, y + i);
+		}
+		loop++;
 	    }
-	    if (loop == 5) {
-		G_plot_line(window.west, y + i,
-			    window.west + (window.east -
-					   window.west) / middlemark, y + i);
-		G_plot_line(window.east -
-			    (window.east - window.west) / middlemark, y + i,
-			    window.east, y + i);
-	    }
-	    else {
-		G_plot_line(window.west, y + i,
-			    window.west + (window.east -
-					   window.west) / shortmark, y + i);
-		G_plot_line(window.east -
-			    (window.east - window.west) / shortmark, y + i,
-			    window.east, y + i);
-	    }
-	    loop++;
+	    y += grid_size;
 	}
-	y += grid_size;
     }
 
     return 0;



More information about the grass-commit mailing list