[GRASS-SVN] r68964 - grass/branches/releasebranch_7_2/display/d.grid

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 14 12:23:18 PDT 2016


Author: annakrat
Date: 2016-07-14 12:23:17 -0700 (Thu, 14 Jul 2016)
New Revision: 68964

Modified:
   grass/branches/releasebranch_7_2/display/d.grid/d.grid.html
   grass/branches/releasebranch_7_2/display/d.grid/fiducial.c
   grass/branches/releasebranch_7_2/display/d.grid/local_proto.h
   grass/branches/releasebranch_7_2/display/d.grid/main.c
   grass/branches/releasebranch_7_2/display/d.grid/plot.c
   grass/branches/releasebranch_7_2/display/d.grid/plotborder.c
Log:
d.grid: backport recent fixes from trunk (r68530, r68542, r68552, r68556)

Modified: grass/branches/releasebranch_7_2/display/d.grid/d.grid.html
===================================================================
--- grass/branches/releasebranch_7_2/display/d.grid/d.grid.html	2016-07-14 19:18:57 UTC (rev 68963)
+++ grass/branches/releasebranch_7_2/display/d.grid/d.grid.html	2016-07-14 19:23:17 UTC (rev 68964)
@@ -3,49 +3,26 @@
 <em>d.grid</em> overlays a grid of user-defined size and
 color in the active display frame on the graphics monitor.
 The grid can be created as a standard rectangular grid or
-a geographic grid. The grid will overlay, not overwrite,
-the contents of the active display frame.
+a geographic grid.
 
 <p>
-<em>d.grid</em> can be run non-interactively or
-interactively.  If the user specifies the grid
-<em>size</em> and (optionally) the grid <em>color</em> on
-the command line the program will run non-interactively; if
-no grid <em>color</em> is given the default will be used.
-Alternately, the user may simply type <b>d.grid</b> on the
-command line; in this case, the program will prompt the
-user for parameter values using the standard GRASS graphical 
-user interface.
-
-
-<h2>NOTES</h2>
-
-<em>d.grid</em> will not erase grids already displayed in
-the active graphics display frame by previous invocations
-of <em>d.grid</em>; multiple invocations of <em>d.grid</em>
-will therefore result in the drawing of multiple grids
-inside the active graphics frame.  (A command like 
-<em><a href="d.erase.html">d.erase</a></em>, which erases the
-entire contents of the active display frame, must be run to
-erase previously drawn grids from the display frame.)
-
-<p>
-If the user provides a <em>-g</em> flag a geographic (projected) grid
-will be drawn. With the <em>-g</em> flag the <em>size</em>
+If the user provides a <b>-g</b> flag a geographic (projected) grid
+will be drawn. With the <b>-g</b> flag the <b>size</b>
 argument accepts both decimal degrees and colon separated
 ddd:mm:ss coordinates (eg. <tt>00:30:00</tt> for half of a degree).
-
-<p>
 A geographic grid cannot be drawn for a <em>latitude/longitude</em> 
 or <em>XY</em> projection.
+
 <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>
+a numerical R:G:B triplet, where component values range from 0-255.
+Grid color can be set with option <b>color</b>. Options <b>text_color</b> and 
+<b>bgcolor</b> set the color of the text and its background.
 
 <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>
+The grid drawing may be turned off by using the <b>-n</b> flag.<br>
+The border drawing may be turned off by using the <b>-b</b> flag.<br>
+The coordinate text may be turned off by using the <b>-t</b> flag.<br>
 
 <p>
 To draw grid lines at different intervals, e.g. at high latitudes, you
@@ -94,6 +71,7 @@
 Geogrid support: Bob Covill<br>
 Border support: Markus Neteler<br>
 Text and RGB support: Hamish Bowman<br>
+Background color implemented as part of GSoC 2016 by Adam Laza, CTU in Prague 
 
 <p>
 <i>Last changed: $Date$</i>

Modified: grass/branches/releasebranch_7_2/display/d.grid/fiducial.c
===================================================================
--- grass/branches/releasebranch_7_2/display/d.grid/fiducial.c	2016-07-14 19:18:57 UTC (rev 68963)
+++ grass/branches/releasebranch_7_2/display/d.grid/fiducial.c	2016-07-14 19:23:17 UTC (rev 68964)
@@ -10,14 +10,14 @@
 void plot_cross(double easting, double northing, int color, double rotation)
 {
     plot_symbol(easting, northing, color, rotation, "basic/cross1",
-		MARK_CROSS);
+                MARK_CROSS);
 }
 
 void plot_fiducial(double easting, double northing, int color,
-		   double rotation)
+                   double rotation)
 {
     plot_symbol(easting, northing, color, rotation + 45.0, "extra/fiducial",
-		MARK_FIDUCIAL);
+                MARK_FIDUCIAL);
 }
 
 void plot_dot(double easting, double northing, int color)
@@ -26,7 +26,7 @@
 }
 
 void plot_symbol(double easting, double northing, int color, double rotation,
-		 char *symbol_name, int mark_type)
+                 char *symbol_name, int mark_type)
 {
     SYMBOL *Symb;
     RGBA_Color *line_color, *fill_color;
@@ -38,8 +38,8 @@
     fill_color = G_malloc(sizeof(RGBA_Color));
 
     if (D_color_number_to_RGB(color, &R, &G, &B) == 0)
-	/* fall back to black on failure */
-	G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
+        /* fall back to black on failure */
+        G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
 
     line_color->r = (unsigned char)R;
     line_color->g = (unsigned char)G;
@@ -48,17 +48,17 @@
 
     fill_color->a = RGBA_COLOR_NONE;
 
-    if(mark_type == MARK_DOT) {
-	size = 5;
-	fill_color->r = (unsigned char)R;
-	fill_color->g = (unsigned char)G;
-	fill_color->b = (unsigned char)B;
-	fill_color->a = RGBA_COLOR_OPAQUE;
+    if (mark_type == MARK_DOT) {
+        size = 5;
+        fill_color->r = (unsigned char)R;
+        fill_color->g = (unsigned char)G;
+        fill_color->b = (unsigned char)B;
+        fill_color->a = RGBA_COLOR_OPAQUE;
     }
 
     Symb = S_read(symbol_name);
     if (!Symb)
-	G_fatal_error(_("Reading symbol"));
+        G_fatal_error(_("Reading symbol"));
 
     S_stroke(Symb, size, rotation, tolerance);
     D_symbol(Symb, easting, northing, line_color, fill_color);

Modified: grass/branches/releasebranch_7_2/display/d.grid/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_2/display/d.grid/local_proto.h	2016-07-14 19:18:57 UTC (rev 68963)
+++ grass/branches/releasebranch_7_2/display/d.grid/local_proto.h	2016-07-14 19:23:17 UTC (rev 68964)
@@ -1,18 +1,19 @@
 #include <grass/gprojects.h>
 
-#define DIRN_BOTH 0 
+#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);
+int plot_grid(double, double, double, int, int, int, int, int, int, double,
+              int);
 int plot_geogrid(double, struct pj_info, struct pj_info, int, int, int, int,
-		 int, double, int);
+                 int, 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);
+                   struct pj_info, struct pj_info);
 void check_coords(double, double, double *, double *, int, struct Cell_head,
-		  struct pj_info, struct pj_info);
+                  struct pj_info, struct pj_info);
 float get_heading(double, double);
 
 /* plotborder.c */

Modified: grass/branches/releasebranch_7_2/display/d.grid/main.c
===================================================================
--- grass/branches/releasebranch_7_2/display/d.grid/main.c	2016-07-14 19:18:57 UTC (rev 68963)
+++ grass/branches/releasebranch_7_2/display/d.grid/main.c	2016-07-14 19:23:17 UTC (rev 68964)
@@ -1,3 +1,4 @@
+
 /****************************************************************
  *
  * MODULE:       d.grid
@@ -32,16 +33,17 @@
     int colorg = 0;
     int colorb = 0;
     int colort = 0;
-    double size = 0., gsize = 0.;	/* initialize to zero */
+    int colorbg = 0;
+    double size = 0., gsize = 0.;       /* initialize to zero */
     double east, north;
     int do_text, fontsize, mark_type, line_width, dirn;
     struct GModule *module;
     struct Option *opt1, *opt2, *opt3, *opt4, *fsize, *tcolor, *lwidth,
-	*direction;
+        *direction, *bgcolor;
     struct Flag *noborder, *notext, *geogrid, *nogrid, *wgs84, *cross,
-	*fiducial, *dot, *align;
-    struct pj_info info_in;	/* Proj structures */
-    struct pj_info info_out;	/* Proj structures */
+        *fiducial, *dot, *align;
+    struct pj_info info_in;     /* Proj structures */
+    struct pj_info info_out;    /* Proj structures */
     struct Cell_head wind;
 
     /* Initialize the GIS calls */
@@ -52,8 +54,8 @@
     G_add_keyword(_("cartography"));
     G_add_keyword(_("graticule"));
     module->description =
-	_("Overlays a user-specified grid "
-	  "in the active display frame on the graphics monitor.");
+        _("Overlays a user-specified grid "
+          "in the active display frame on the graphics monitor.");
 
     opt2 = G_define_option();
     opt2->key = "size";
@@ -61,9 +63,10 @@
     opt2->type = TYPE_STRING;
     opt2->required = YES;
     opt2->label = _("Size of grid to be drawn (in map units)");
-    opt2->description = _("0 for north-south resolution of the current region. "
-                          "In map units or DDD:MM:SS format. "
-			  "Example: \"1000\" or \"0:10\"");
+    opt2->description =
+        _("0 for north-south resolution of the current region. "
+          "In map units or DDD:MM:SS format. "
+          "Example: \"1000\" or \"0:10\"");
 
     opt3 = G_define_standard_option(G_OPT_M_COORDS);
     opt3->key = "origin";
@@ -78,7 +81,7 @@
     direction->answer = "both";
     direction->options = "both,east-west,north-south";
     direction->description =
-	_("Draw only east-west lines, north-south lines, or both ");
+        _("Draw only east-west lines, north-south lines, or both ");
     direction->guisection = _("Disable");
 
     lwidth = G_define_option();
@@ -103,6 +106,12 @@
     tcolor->label = _("Text color");
     tcolor->guisection = _("Color");
 
+    bgcolor = G_define_standard_option(G_OPT_CN);
+    bgcolor->key = "bgcolor";
+    bgcolor->answer = "none";
+    bgcolor->label = _("Background color");
+    bgcolor->guisection = _("Color");
+
     fsize = G_define_option();
     fsize->key = "fontsize";
     fsize->type = TYPE_INTEGER;
@@ -113,18 +122,19 @@
 
     align = G_define_flag();
     align->key = 'a';
-    align->description = _("Align the origin to the east-north corner of the current region");
+    align->description =
+        _("Align the origin to the east-north corner of the current region");
 
     geogrid = G_define_flag();
     geogrid->key = 'g';
     geogrid->description =
-	_("Draw geographic grid (referenced to current ellipsoid)");
+        _("Draw geographic grid (referenced to current ellipsoid)");
     geogrid->guisection = _("Draw");
 
     wgs84 = G_define_flag();
     wgs84->key = 'w';
     wgs84->description =
-	_("Draw geographic grid (referenced to WGS84 ellipsoid)");
+        _("Draw geographic grid (referenced to WGS84 ellipsoid)");
     wgs84->guisection = _("Draw");
 
     cross = G_define_flag();
@@ -141,7 +151,7 @@
     fiducial->key = 'f';
     fiducial->description = _("Draw fiducial marks instead of grid lines");
     fiducial->guisection = _("Draw");
-    
+
     nogrid = G_define_flag();
     nogrid->key = 'n';
     nogrid->description = _("Disable grid drawing");
@@ -159,131 +169,141 @@
 
     /* Check command line */
     if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
+        exit(EXIT_FAILURE);
 
 
     /* do some checking */
     if (nogrid->answer && noborder->answer)
-	G_fatal_error(_("Both grid and border drawing are disabled"));
+        G_fatal_error(_("Both grid and border drawing are disabled"));
     if (wgs84->answer)
-	geogrid->answer = 1;	/* -w implies -g */
+        geogrid->answer = 1;    /* -w implies -g */
     if (geogrid->answer && G_projection() == PROJECTION_LL)
-	G_fatal_error(_("Geo-grid option not available for LL projection, use without -g/-w"));
+        G_fatal_error(_("Geo-grid option not available for LL projection, use without -g/-w"));
     if (geogrid->answer && G_projection() == PROJECTION_XY)
-	G_fatal_error(_("Geo-grid option not available for XY projection, use without -g/-w"));
+        G_fatal_error(_("Geo-grid option not available for XY projection, use without -g/-w"));
 
     if (notext->answer)
-	do_text = FALSE;
+        do_text = FALSE;
     else
-	do_text = TRUE;
+        do_text = TRUE;
 
     if (lwidth->answer) {
-	line_width = atoi(lwidth->answer);
-	if(line_width < 0 || line_width > 1e3)
-	    G_fatal_error("Invalid line width");
+        line_width = atoi(lwidth->answer);
+        if (line_width < 0 || line_width > 1e3)
+            G_fatal_error("Invalid line width");
     }
     else
-	line_width = 0;
+        line_width = 0;
 
     fontsize = atoi(fsize->answer);
 
     mark_type = MARK_GRID;
     if (cross->answer + fiducial->answer + dot->answer > 1)
-	G_fatal_error(_("Choose a single mark style"));
+        G_fatal_error(_("Choose a single mark style"));
     if (cross->answer)
-	mark_type = MARK_CROSS;
+        mark_type = MARK_CROSS;
     if (fiducial->answer)
-	mark_type = MARK_FIDUCIAL;
+        mark_type = MARK_FIDUCIAL;
     if (dot->answer)
-	mark_type = MARK_DOT;
+        mark_type = MARK_DOT;
 
     if (G_strcasecmp(direction->answer, "both") == 0)
-	dirn = DIRN_BOTH;
+        dirn = DIRN_BOTH;
     else if (G_strcasecmp(direction->answer, "east-west") == 0)
-	dirn = DIRN_LAT;
+        dirn = DIRN_LAT;
     else if (G_strcasecmp(direction->answer, "north-south") == 0)
-	dirn = DIRN_LON;
+        dirn = DIRN_LON;
     else
-	G_fatal_error("Invalid direction: %s", direction->answer);
+        G_fatal_error("Invalid direction: %s", direction->answer);
 
     if (align->answer || strcmp(opt2->answer, "0") == 0)
-	G_get_element_window(&wind, "", "WIND", G_mapset());
+        G_get_element_window(&wind, "", "WIND", G_mapset());
 
     if (strcmp(opt2->answer, "0") == 0) {
-	if (geogrid->answer)
-	    gsize = wind.ns_res;
-	else
-	    size = wind.ns_res;
-    } else {
+        if (geogrid->answer)
+            gsize = wind.ns_res;
+        else
+            size = wind.ns_res;
+    }
+    else {
         /* get grid size */
         if (geogrid->answer) {
-	    if (!G_scan_resolution(opt2->answer, &gsize, PROJECTION_LL) ||
-    	        gsize <= 0.0)
-    	        G_fatal_error(_("Invalid geo-grid size <%s>"), opt2->answer);
+            if (!G_scan_resolution(opt2->answer, &gsize, PROJECTION_LL) ||
+                gsize <= 0.0)
+                G_fatal_error(_("Invalid geo-grid size <%s>"), opt2->answer);
         }
         else {
-    	    if (!G_scan_resolution(opt2->answer, &size, G_projection()) ||
-    	        size <= 0.0)
-    	        G_fatal_error(_("Invalid grid size <%s>"), opt2->answer);
+            if (!G_scan_resolution(opt2->answer, &size, G_projection()) ||
+                size <= 0.0)
+                G_fatal_error(_("Invalid grid size <%s>"), opt2->answer);
         }
     }
 
     if (align->answer) {
-	/* reduce accumulated errors when ew_res is not the same as ns_res. */
-	struct Cell_head w;
+        /* reduce accumulated errors when ew_res is not the same as ns_res. */
+        struct Cell_head w;
 
-	G_get_set_window(&w);
-	east = wind.west + (int)((w.west - wind.west) / wind.ew_res) * wind.ew_res;
-	north = wind.south + (int)((w.south - wind.south) / wind.ns_res) * wind.ns_res;
-    } else {
+        G_get_set_window(&w);
+        east =
+            wind.west +
+            (int)((w.west - wind.west) / wind.ew_res) * wind.ew_res;
+        north =
+            wind.south +
+            (int)((w.south - wind.south) / wind.ns_res) * wind.ns_res;
+    }
+    else {
         /* get grid easting start */
         if (!G_scan_easting(opt3->answers[0], &east, G_projection())) {
-    	    G_usage();
-    	    G_fatal_error(_("Illegal east coordinate <%s>"), opt3->answers[0]);
+            G_usage();
+            G_fatal_error(_("Illegal east coordinate <%s>"),
+                          opt3->answers[0]);
         }
-    
+
         /* get grid northing start */
         if (!G_scan_northing(opt3->answers[1], &north, G_projection())) {
-    	    G_usage();
-    	    G_fatal_error(_("Illegal north coordinate <%s>"), opt3->answers[1]);
+            G_usage();
+            G_fatal_error(_("Illegal north coordinate <%s>"),
+                          opt3->answers[1]);
         }
     }
 
     /* Setup driver and check important information */
     D_open_driver();
-    
+
     /* Parse and select grid color */
     colorg = D_parse_color(opt1->answer, FALSE);
     /* Parse and select border color */
     colorb = D_parse_color(opt4->answer, FALSE);
     /* Parse and select text color */
     colort = D_parse_color(tcolor->answer, FALSE);
+    /* Parse and select background color */
+    colorbg = D_parse_color(bgcolor->answer, TRUE);
 
 
     D_setup(0);
 
     /* draw grid */
     if (!nogrid->answer) {
-	if (geogrid->answer) {
-	    /* 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, dirn);
-	}
-	else {
-	    /* Do the grid plotting */
-	    plot_grid(size, east, north, do_text, colorg, colort, fontsize,
-		      mark_type, line_width, dirn);
-	}
+        if (geogrid->answer) {
+            /* initialzie proj stuff */
+            init_proj(&info_in, &info_out, wgs84->answer);
+            plot_geogrid(gsize, info_in, info_out, do_text, colorg, colort,
+                         colorbg, fontsize, mark_type, line_width, dirn);
+        }
+        else {
+            /* Do the grid plotting */
+            plot_grid(size, east, north, do_text, colorg, colort, colorbg,
+                      fontsize, mark_type, line_width, dirn);
+        }
     }
 
     /* Draw border */
     if (!noborder->answer) {
-	/* Set border color */
-	D_use_color(colorb);
+        /* Set border color */
+        D_use_color(colorb);
 
-	/* Do the border plotting */
-	plot_border(size, east, north, dirn);
+        /* Do the border plotting */
+        plot_border(size, east, north, dirn);
     }
 
     D_save_command(G_recreate_command());

Modified: grass/branches/releasebranch_7_2/display/d.grid/plot.c
===================================================================
--- grass/branches/releasebranch_7_2/display/d.grid/plot.c	2016-07-14 19:18:57 UTC (rev 68963)
+++ grass/branches/releasebranch_7_2/display/d.grid/plot.c	2016-07-14 19:23:17 UTC (rev 68964)
@@ -10,63 +10,45 @@
 
 
 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, int direction)
+              int gcolor, int tcolor, int bgcolor, int fontsize,
+              int mark_type, double line_width, int direction)
 {
     double x, y, y0;
     double e1, e2;
     struct Cell_head window;
     double row_dist, colm_dist;
     char text[128];
+    double tx, ty, bt, bb, bl, br, w, h;
 
     G_get_set_window(&window);
 
     /* pull right and bottom edges back one pixel; display lib bug? */
     row_dist = D_d_to_u_row(0.) - D_d_to_u_row(1.);
     colm_dist = D_d_to_u_col(1.) - D_d_to_u_col(0.);
-/*    window.south += row_dist;
-      window.east -= colm_dist;
- */
+    /*    window.south += row_dist;
+       window.east -= colm_dist;
+     */
 
     /* Draw vertical grids */
     if (window.west > east)
-	x = ceil((window.west - east) / grid_size) * grid_size + east;
+        x = ceil((window.west - east) / grid_size) * grid_size + east;
     else
-	x = east - ceil((east - window.west) / grid_size) * grid_size;
+        x = east - ceil((east - window.west) / grid_size) * grid_size;
 
     if (direction != DIRN_LAT) {
-	while (x <= window.east) {
-	    if (mark_type == MARK_GRID) {
-		D_use_color(gcolor);
-		if (line_width)
-		    D_line_width(line_width);
-		D_line_abs(x, window.north, x, window.south);
-		D_line_width(0);    /* reset so text doesn't use it */
-	    }
-
-	    if (do_text) {
-		D_use_color(tcolor);
-		G_format_easting(x, text, G_projection());
-		D_text_rotation(270.0);
-		D_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)
-		 */
-		D_pos_abs(x + 4.5 * D_get_d_to_u_xconv(),
-			   D_get_u_south()
-			   - D_get_d_to_u_yconv() * (strlen(text) * fontsize * 0.81 + 7.5));
-
-		D_text(text);
-	    }
-	    x += grid_size;
-	}
-	D_text_rotation(0.0);	    /* reset */
+        while (x <= window.east) {
+            if (mark_type == MARK_GRID) {
+                D_use_color(gcolor);
+                if (line_width)
+                    D_line_width(line_width);
+                D_line_abs(x, window.north, x, window.south);
+                D_line_width(0);        /* reset so text doesn't use it */
+            }
+            x += grid_size;
+        }
+        D_text_rotation(0.0);   /* reset */
     }
 
-
     /* Draw horizontal grids
      *
      * For latlon, must draw in shorter sections
@@ -77,70 +59,173 @@
     e2 = (window.west * 2 + window.east) / 3;
 
     if (window.south > north)
-	y = ceil((window.south - north) / grid_size) * grid_size + north;
+        y = ceil((window.south - north) / grid_size) * grid_size + north;
     else
-	y = north - ceil((north - window.south) / grid_size) * grid_size;
+        y = north - ceil((north - window.south) / grid_size) * grid_size;
 
     if (direction != DIRN_LON) {
-	while (y <= window.north) {
-	    if (mark_type == MARK_GRID) {
-		D_use_color(gcolor);
-		if (line_width)
-		    D_line_width(line_width);
-		D_line_abs(window.east, y, e1, y);
-		D_line_abs(e1, y, e2, y);
-		D_line_abs(e2, y, window.west, y);
-		D_line_width(0);    /* reset so text doesn't use it */
-	    }
+        while (y <= window.north) {
+            if (mark_type == MARK_GRID) {
+                D_use_color(gcolor);
+                if (line_width)
+                    D_line_width(line_width);
+                D_line_abs(window.east, y, e1, y);
+                D_line_abs(e1, y, e2, y);
+                D_line_abs(e2, y, window.west, y);
+                D_line_width(0);        /* reset so text doesn't use it */
+            }
+            y += grid_size;
+        }
+        D_text_rotation(0.0);
+    }
 
-	    if (do_text) {
-		D_use_color(tcolor);
-		G_format_northing(y, text, G_projection());
-		D_text_size(fontsize, fontsize);
+    /* draw marks not grid lines */
+    if (mark_type != MARK_GRID) {
+        /* reset x and y */
+        if (window.west > east)
+            x = ceil((window.west - east) / grid_size) * grid_size + east;
+        else
+            x = east - ceil((east - window.west) / grid_size) * grid_size;
+        if (window.south > north)
+            y0 = ceil((window.south - north) / grid_size) * grid_size + north;
+        else
+            y0 = north - ceil((north - window.south) / grid_size) * grid_size;
 
-		/* 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.
-		 */
-		D_pos_abs(
-		    D_get_u_east()
-		    - D_get_d_to_u_xconv() * (strlen(text) * fontsize * 0.81 + 7.5),
-		    y - D_get_d_to_u_yconv() * 4.5);
+        /* plot marks */
+        while (x <= window.east) {
+            y = y0;             /* reset */
+            while (y <= window.north) {
+                if (mark_type == MARK_CROSS)
+                    plot_cross(x, y, gcolor, 0.0);
+                else if (mark_type == MARK_FIDUCIAL)
+                    plot_fiducial(x, y, gcolor, 0.0);
+                else if (mark_type == MARK_DOT)
+                    plot_dot(x, y, gcolor);
+                y += grid_size;
+            }
+            x += grid_size;
+        }
+    }
 
-		D_text(text);
-	    }
-	    y += grid_size;
-	}
+    /* Draw vertical labels */
+    if (do_text) {
+        if (window.west > east)
+            x = ceil((window.west - east) / grid_size) * grid_size + east;
+        else
+            x = east - ceil((east - window.west) / grid_size) * grid_size;
+
+        if (direction != DIRN_LAT) {
+            while (x <= window.east) {
+                D_use_color(tcolor);
+                G_format_easting(x, text, G_projection());
+                D_text_rotation(270.0);
+                D_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)
+                 */
+                D_pos_abs(x + 4.5 * D_get_d_to_u_xconv(), D_get_u_south()
+                          - D_get_d_to_u_yconv() * (strlen(text)
+                          * fontsize * 0.81 + 7.5));
+
+                tx = x + 4.5 * D_get_d_to_u_xconv();
+                ty = D_get_u_south() -
+                    D_get_d_to_u_yconv() * (strlen(text) * fontsize * 0.81 + 7.5);
+
+                if (bgcolor != 0) {
+                    D_get_text_box(text, &bt, &bb, &bl, &br);
+                    w = br - bl;
+                    h = bt - bb;
+
+                    if (w > 0)
+                        w += 0.2 * fontsize * fabs(D_get_d_to_u_xconv());
+                    else  /* D_text() does not draw " ". */
+                        w = 0.8 * fontsize * fabs(D_get_d_to_u_xconv());
+                    if (h > 0)
+                        h += 0.2 * fontsize * fabs(D_get_d_to_u_yconv());
+                    else  /* D_text() does not draw " ". */
+                        h = 0.8 * fontsize * fabs(D_get_d_to_u_yconv());
+
+                    bl = tx - w/2;
+                    bt = ty + h/10;
+                    br = tx + w + w/2;
+                    bb = ty - h - h/10;
+
+                    D_use_color(bgcolor);
+                    D_box_abs(bl, bt, br, bb);
+                }
+
+                D_use_color(tcolor);
+                D_pos_abs(tx, ty);
+                D_text(text);
+                x += grid_size;
+            }
+            D_text_rotation(0.0);   /* reset */
+        }
     }
 
+    /* Draw horizontal labels */
+    if (do_text) {
+        if (window.south > north)
+            y = ceil((window.south - north) / grid_size) * grid_size + north;
+        else
+            y = north - ceil((north - window.south) / grid_size) * grid_size;
 
-    /* draw marks not grid lines */
-    if (mark_type != MARK_GRID) {
-	/* reset x and y */
-	if (window.west > east)
-	    x = ceil((window.west - east) / grid_size) * grid_size + east;
-	else
-	    x = east - ceil((east - window.west) / grid_size) * grid_size;
-	if (window.south > north)
-	    y0 = ceil((window.south - north) / grid_size) * grid_size + north;
-	else
-	    y0 = north - ceil((north - window.south) / grid_size) * grid_size;
+        if (direction != DIRN_LON) {
+            while (y <= window.north) {
 
-	/* plot marks */
-	while (x <= window.east) {
-	    y = y0;		/* reset */
-	    while (y <= window.north) {
-		if (mark_type == MARK_CROSS)
-		    plot_cross(x, y, gcolor, 0.0);
-		else if (mark_type == MARK_FIDUCIAL)
-		    plot_fiducial(x, y, gcolor, 0.0);
-		else if (mark_type == MARK_DOT)
-		    plot_dot(x, y, gcolor);
-		y += grid_size;
-	    }
-	    x += grid_size;
-	}
+                D_use_color(tcolor);
+                G_format_northing(y, text, G_projection());
+                D_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.
+                 */
+                D_pos_abs(D_get_u_east()
+                          -
+                          D_get_d_to_u_xconv() * (strlen(text) * fontsize *
+                                                  0.81 + 7.5),
+                          y - D_get_d_to_u_yconv() * 4.5);
+
+                tx = D_get_u_east() -
+                     D_get_d_to_u_xconv() * (strlen(text) * fontsize * 0.81 +
+                                             7.5);
+                ty = y - D_get_d_to_u_yconv() * 4.5;
+
+                if (bgcolor != 0) {
+                    D_get_text_box(text, &bt, &bb, &bl, &br);
+                    w = br - bl;
+                    h = bt - bb;
+
+                    if (w > 0)
+                        w += 0.2 * fontsize * fabs(D_get_d_to_u_xconv());
+                    else  /* D_text() does not draw " ". */
+                        w = 0.8 * fontsize * fabs(D_get_d_to_u_xconv());
+                    if (h > 0)
+                        h += 0.2 * fontsize * fabs(D_get_d_to_u_yconv());
+                    else  /* D_text() does not draw " ". */
+                        h = 0.8 * fontsize * fabs(D_get_d_to_u_yconv());
+
+                    bl = tx - w/10;
+                    bt = ty + h + h/2;
+                    br = tx + w + w/10;
+                    bb = ty - h/2;
+                    D_use_color(bgcolor);
+                    D_box_abs(bl, bt, br, bb);
+                }
+
+                D_use_color(tcolor);
+                D_pos_abs(tx, ty);
+                D_text(text);
+
+                y += grid_size;
+            }
+            D_text_rotation(0.0);
+        }
     }
 
     return 0;
@@ -148,8 +233,8 @@
 
 
 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 direction)
+                 int do_text, int gcolor, int tcolor, int bgcolor, int fontsize,
+                 int mark_type, double line_width, int direction)
 {
     double g;
     double e1, e2, n1, n2;
@@ -165,6 +250,7 @@
     double row_dist, colm_dist;
     float font_angle;
     struct Cell_head window;
+    double tx, ty, bt, bb, bl, br, w, h;
 
     /* geo current region */
     G_get_set_window(&window);
@@ -186,150 +272,269 @@
     g = floor(north / size) * size;
     e1 = east;
     for (j = 0; g >= south; j++, g -= size) {
-	start_coord = -9999.;
-	if (g == north || g == south || direction == DIRN_LON)
-	    continue;
+        start_coord = -9999.;
+        if (g == north || g == south || direction == DIRN_LON)
+            continue;
 
-	/* Set grid color */
-	D_use_color(gcolor);
+        /* Set grid color */
+        D_use_color(gcolor);
 
-	for (ll = 0; ll < SEGS; ll++) {
-	    n1 = n2 = g;
-	    e1 = west + (ll * ((east - west) / SEGS));
-	    e2 = e1 + ((east - west) / SEGS);
-	    if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+        for (ll = 0; ll < SEGS; ll++) {
+            n1 = n2 = g;
+            e1 = west + (ll * ((east - west) / SEGS));
+            e2 = e1 + ((east - west) / SEGS);
+            if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
+                G_fatal_error(_("Error in pj_do_proj"));
 
-	    check_coords(e1, n1, &lon, &lat, 1, window, info_in, info_out);
-	    e1 = lon;
-	    n1 = lat;
-	    if (pj_do_proj(&e2, &n2, &info_in, &info_out) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+            check_coords(e1, n1, &lon, &lat, 1, window, info_in, info_out);
+            e1 = lon;
+            n1 = lat;
+            if (pj_do_proj(&e2, &n2, &info_in, &info_out) < 0)
+                G_fatal_error(_("Error in pj_do_proj"));
 
-	    check_coords(e2, n2, &lon, &lat, 1, window, info_in, info_out);
-	    e2 = lon;
-	    n2 = lat;
-	    if (start_coord == -9999.) {
-		start_coord = n1;
-		font_angle = get_heading((e1 - e2), (n1 - n2));
-	    }
+            check_coords(e2, n2, &lon, &lat, 1, window, info_in, info_out);
+            e2 = lon;
+            n2 = lat;
+            if (start_coord == -9999.) {
+                start_coord = n1;
+                font_angle = get_heading((e1 - e2), (n1 - n2));
+            }
 
-	    if (line_width)
-		D_line_width(line_width);
+            if (line_width)
+                D_line_width(line_width);
 
-	    if (mark_type == MARK_GRID)
-		D_line_abs(e1, n1, e2, n2);
+            if (mark_type == MARK_GRID)
+                D_line_abs(e1, n1, e2, n2);
 
-	    D_line_width(0);
-	}
+            D_line_width(0);
+        }
+        }
 
-	if (do_text) {
-	    /* Set text color */
-	    D_use_color(tcolor);
-
-	    G_format_northing(g, text, PROJECTION_LL);
-	    D_text_rotation(font_angle);
-	    D_text_size(fontsize, fontsize);
-	    D_pos_abs(D_get_u_west() + D_get_d_to_u_xconv() * border_off,
-		      start_coord - D_get_d_to_u_yconv() * grid_off);
-	    D_text(text);
-	}
-    }
-
     /* Lines of Longitude */
     g = floor(east / size) * size;
     n1 = north;
     for (j = 0; g > west; j++, g -= size) {
-	start_coord = -9999.;
-	extra_y_off = 0.0;
-	if (g == east || g == west || direction == DIRN_LAT)
-	    continue;
+        start_coord = -9999.;
+        extra_y_off = 0.0;
+        if (g == east || g == west || direction == DIRN_LAT)
+            continue;
 
-	/* Set grid color */
-	D_use_color(gcolor);
+        /* Set grid color */
+        D_use_color(gcolor);
 
-	for (ll = 0; ll < SEGS; ll++) {
-	    e1 = e2 = g;
-	    n1 = north - (ll * ((north - south) / SEGS));
-	    n2 = n1 - ((north - south) / SEGS);
-	    /*
-	       n1 = south + (ll *((north - south)/SEGS));
-	       n2 = n1 + ((north - south)/SEGS);
-	     */
-	    if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+        for (ll = 0; ll < SEGS; ll++) {
+            e1 = e2 = g;
+            n1 = north - (ll * ((north - south) / SEGS));
+            n2 = n1 - ((north - south) / SEGS);
+            /*
+               n1 = south + (ll *((north - south)/SEGS));
+               n2 = n1 + ((north - south)/SEGS);
+             */
+            if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
+                G_fatal_error(_("Error in pj_do_proj"));
 
-	    check_coords(e1, n1, &lon, &lat, 2, window, info_in, info_out);
-	    e1 = lon;
-	    n1 = lat;
-	    if (pj_do_proj(&e2, &n2, &info_in, &info_out) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+            check_coords(e1, n1, &lon, &lat, 2, window, info_in, info_out);
+            e1 = lon;
+            n1 = lat;
+            if (pj_do_proj(&e2, &n2, &info_in, &info_out) < 0)
+                G_fatal_error(_("Error in pj_do_proj"));
 
-	    check_coords(e2, n2, &lon, &lat, 2, window, info_in, info_out);
-	    e2 = lon;
-	    n2 = lat;
+            check_coords(e2, n2, &lon, &lat, 2, window, info_in, info_out);
+            e2 = lon;
+            n2 = lat;
 
-	    if ((start_coord == -9999.) && (D_u_to_a_row(n1) > 0)) {
-		font_angle = get_heading((e1 - e2), (n1 - n2));
-		start_coord = e1;
+            if ((start_coord == -9999.) && (D_u_to_a_row(n1) > 0)) {
+                font_angle = get_heading((e1 - e2), (n1 - n2));
+                start_coord = e1;
 
-		/* font rotates by bottom-left corner, try to keep top-left cnr on screen */
-		if (font_angle - 270 > 0) {
-		    extra_y_off = sin((font_angle - 270) * M_PI/180) * fontsize;
-		    if (D_u_to_d_row(n1) - D_get_d_north() < extra_y_off + grid_off)
-			start_coord = -9999.;  /* wait until the next point south */
-		}
-	    }
+                /* font rotates by bottom-left corner, try to keep top-left cnr on screen */
+                if (font_angle - 270 > 0) {
+                    extra_y_off =
+                        sin((font_angle - 270) * M_PI / 180) * fontsize;
+                    if (D_u_to_d_row(n1) - D_get_d_north() <
+                        extra_y_off + grid_off)
+                        start_coord = -9999.;   /* wait until the next point south */
+                }
+            }
 
-	    if (line_width)
-		D_line_width(line_width);
+            if (line_width)
+                D_line_width(line_width);
 
-	    if (mark_type == MARK_GRID)
-		D_line_abs(e1, n1, e2, n2);
+            if (mark_type == MARK_GRID)
+                D_line_abs(e1, n1, e2, n2);
 
-	    D_line_width(0);
-	}
-	if (do_text) {
-	    /* Set text color */
-	    D_use_color(tcolor);
+            D_line_width(0);
+        }
+        }
+    D_text_rotation(0.0);       /* reset */
 
-	    G_format_easting(g, text, PROJECTION_LL);
-	    D_text_rotation(font_angle);
-	    D_text_size(fontsize, fontsize);
-	    D_pos_abs(start_coord + D_get_d_to_u_xconv() * (grid_off + 1.5),
-		      D_get_u_north() + D_get_d_to_u_yconv() *
-		      (border_off + extra_y_off));
-	    D_text(text);
-	}
-    }
-
-    D_text_rotation(0.0);	/* reset */
-
     /* draw marks not grid lines */
     if (mark_type != MARK_GRID) {
-	G_warning(_("Geo-grid option only available for LL projection, use without -g/-w"));
+        G_warning(_("Geo-grid option only available for LL projection, use without -g/-w"));
 #ifdef TODO
-	e1 = combine above;
-	n1 = combine above;
+        e1 = combine above;
+        n1 = combine above;
 
-	/* plot marks */
-	while (e1 <= window.east) {
-	    n1 = y0;		/* reset */
-	    while (n1 <= window.north) {
-		if (mark_type == MARK_CROSS)
-		    plot_cross(e1, n1, gcolor, 0.0);
-		else if (mark_type == MARK_FIDUCIAL)
-		    plot_fiducial(e1, n1, gcolor, 0.0);
-		else if (mark_type == MARK_DOT)
-		    plot_dot(e1, n1, gcolor);
-		n1 += grid_size;
-	    }
-	    e1 += grid_size;
-	}
+        /* plot marks */
+        while (e1 <= window.east) {
+            n1 = y0;            /* reset */
+            while (n1 <= window.north) {
+                if (mark_type == MARK_CROSS)
+                    plot_cross(e1, n1, gcolor, 0.0);
+                else if (mark_type == MARK_FIDUCIAL)
+                    plot_fiducial(e1, n1, gcolor, 0.0);
+                else if (mark_type == MARK_DOT)
+                    plot_dot(e1, n1, gcolor);
+                n1 += grid_size;
+            }
+            e1 += grid_size;
+        }
 #endif
-    /* also TODO: rotate cross and fiducial marks by the converge angle; see g.region -n */
+        /* also TODO: rotate cross and fiducial marks by the converge angle; see g.region -n */
     }
 
+    /* geo current region */
+    G_get_set_window(&window);
+
+    /* Adjust south and east back by one pixel for display bug? */
+    row_dist = D_d_to_u_row(0.) - D_d_to_u_row(1.);
+    colm_dist = D_d_to_u_col(1.) - D_d_to_u_col(0.);
+    window.south += row_dist;
+    window.east -= colm_dist;
+
+    /* get lat long min max */
+    /* probably need something like boardwalk ?? */
+    get_ll_bounds(&west, &east, &south, &north, window, info_in, info_out);
+
+    G_debug(3, "REGION BOUNDS N=%f S=%f E=%f W=%f", north, south, east, west);
+
+
+    /* Labels of Latitude */
+    if (do_text) {
+        g = floor(north / size) * size;
+        e1 = east;
+        for (j = 0; g >= south; j++, g -= size) {
+            start_coord = -9999.;
+            if (g == north || g == south || direction == DIRN_LON)
+                continue;
+
+            /* Set grid color */
+            for (ll = 0; ll < SEGS; ll++) {
+                n1 = n2 = g;
+                e1 = west + (ll * ((east - west) / SEGS));
+                e2 = e1 + ((east - west) / SEGS);
+                if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
+                    G_fatal_error(_("Error in pj_do_proj"));
+
+                check_coords(e1, n1, &lon, &lat, 1, window, info_in, info_out);
+                e1 = lon;
+                n1 = lat;
+                if (pj_do_proj(&e2, &n2, &info_in, &info_out) < 0)
+                    G_fatal_error(_("Error in pj_do_proj"));
+
+                check_coords(e2, n2, &lon, &lat, 1, window, info_in, info_out);
+                e2 = lon;
+                n2 = lat;
+                if (start_coord == -9999.) {
+                    start_coord = n1;
+                    font_angle = get_heading((e1 - e2), (n1 - n2));
+                }
+            }
+
+            G_format_northing(g, text, PROJECTION_LL);
+            D_text_rotation(font_angle);
+            D_text_size(fontsize, fontsize);
+            tx = D_get_u_west() + D_get_d_to_u_xconv() * border_off;
+            ty = start_coord - D_get_d_to_u_yconv() * grid_off;
+
+            if (bgcolor != 0) {
+                D_get_text_box(text, &bt, &bb, &bl, &br);
+                w = br - bl;
+                h = bt - bb;
+                bl = tx - w/10;
+                bt = ty + h + h/2;
+                br = tx + w + w/10;
+                bb = ty - h/2;
+                D_use_color(bgcolor);
+                D_box_abs(bl, bt, br, bb);
+            }
+
+            D_use_color(tcolor);
+            D_pos_abs(tx, ty);
+            D_text(text);
+        }
+    }
+
+
+    /* Labels of Longitude */
+    if (do_text) {
+        g = floor(east / size) * size;
+        n1 = north;
+        for (j = 0; g > west; j++, g -= size) {
+            start_coord = -9999.;
+            extra_y_off = 0.0;
+            if (g == east || g == west || direction == DIRN_LAT)
+                continue;
+
+            for (ll = 0; ll < SEGS; ll++) {
+                e1 = e2 = g;
+                n1 = north - (ll * ((north - south) / SEGS));
+                n2 = n1 - ((north - south) / SEGS);
+
+                if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
+                    G_fatal_error(_("Error in pj_do_proj"));
+
+                check_coords(e1, n1, &lon, &lat, 2, window, info_in, info_out);
+                e1 = lon;
+                n1 = lat;
+                if (pj_do_proj(&e2, &n2, &info_in, &info_out) < 0)
+                    G_fatal_error(_("Error in pj_do_proj"));
+
+                check_coords(e2, n2, &lon, &lat, 2, window, info_in, info_out);
+                e2 = lon;
+                n2 = lat;
+
+                if ((start_coord == -9999.) && (D_u_to_a_row(n1) > 0)) {
+                    font_angle = get_heading((e1 - e2), (n1 - n2));
+                    start_coord = e1;
+
+                    /* font rotates by bottom-left corner, try to keep top-left cnr on screen */
+                    if (font_angle - 270 > 0) {
+                        extra_y_off =
+                            sin((font_angle - 270) * M_PI / 180) * fontsize;
+                        if (D_u_to_d_row(n1) - D_get_d_north() <
+                            extra_y_off + grid_off)
+                            start_coord = -9999.;   /* wait until the next point south */
+                    }
+                }
+            }
+
+            G_format_easting(g, text, PROJECTION_LL);
+            D_text_rotation(font_angle);
+            D_text_size(fontsize, fontsize);
+            tx = start_coord + D_get_d_to_u_xconv() * (grid_off + 1.5);
+            ty = D_get_u_north() + D_get_d_to_u_yconv() * (border_off +
+                                                           extra_y_off);
+
+            if (bgcolor != 0) {
+                D_get_text_box(text, &bt, &bb, &bl, &br);
+                w = br - bl;
+                h = bt - bb;
+                bl = tx - w/2;
+                bt = ty + h/10;
+                br = tx + w + w/2;
+                bb = ty - h - h/10;
+                D_use_color(bgcolor);
+                D_box_abs(bl, bt, br, bb);
+            }
+
+            D_use_color(tcolor);
+            D_pos_abs(tx, ty);
+            D_text(text);
+        }
+        D_text_rotation(0.0);       /* reset */
+    }
+
     return 0;
 
 }
@@ -346,44 +551,44 @@
     out_proj_keys = G_get_projinfo();
     out_unit_keys = G_get_projunits();
     if (pj_get_kv(info_out, out_proj_keys, out_unit_keys) < 0)
-	G_fatal_error(_("Can't get projection key values of current location"));
+        G_fatal_error(_("Can't get projection key values of current location"));
 
     /* In Info */
     if (!wgs84) {
-	/* Set lat/long to same ellipsoid as location if we're not looking
-	 * for the WGS84 values */
-	if (GPJ_get_equivalent_latlong(info_in, info_out) < 0)
-	    G_fatal_error(_("Unable to set up lat/long projection parameters"));
+        /* Set lat/long to same ellipsoid as location if we're not looking
+         * for the WGS84 values */
+        if (GPJ_get_equivalent_latlong(info_in, info_out) < 0)
+            G_fatal_error(_("Unable to set up lat/long projection parameters"));
 
     }
     else {
-	struct Key_Value *in_proj_info, *in_unit_info;
-	char buff[256], dum[256];
+        struct Key_Value *in_proj_info, *in_unit_info;
+        char buff[256], dum[256];
 
-	in_proj_info = G_create_key_value();
-	in_unit_info = G_create_key_value();
+        in_proj_info = G_create_key_value();
+        in_unit_info = G_create_key_value();
 
-	/* Check that datumparams are defined for this location (otherwise
-	 * the WGS84 values would be meaningless), and if they are set the 
-	 * input datum to WGS84 */
-	if (G_get_datumparams_from_projinfo(out_proj_keys, buff, dum) < 0)
-	    G_fatal_error(_("WGS84 grid output not possible as this location does not contain\n"
-			   "datum transformation parameters. Try running g.setproj."));
-	else
-	    G_set_key_value("datum", "wgs84", in_proj_info);
+        /* Check that datumparams are defined for this location (otherwise
+         * the WGS84 values would be meaningless), and if they are set the 
+         * input datum to WGS84 */
+        if (G_get_datumparams_from_projinfo(out_proj_keys, buff, dum) < 0)
+            G_fatal_error(_("WGS84 grid output not possible as this location does not contain\n"
+                           "datum transformation parameters. Try running g.setproj."));
+        else
+            G_set_key_value("datum", "wgs84", in_proj_info);
 
-	/* set input projection to lat/long */
-	G_set_key_value("proj", "ll", in_proj_info);
+        /* set input projection to lat/long */
+        G_set_key_value("proj", "ll", in_proj_info);
 
-	G_set_key_value("unit", "degree", in_unit_info);
-	G_set_key_value("units", "degrees", in_unit_info);
-	G_set_key_value("meters", "1.0", in_unit_info);
+        G_set_key_value("unit", "degree", in_unit_info);
+        G_set_key_value("units", "degrees", in_unit_info);
+        G_set_key_value("meters", "1.0", in_unit_info);
 
-	if (pj_get_kv(info_in, in_proj_info, in_unit_info) < 0)
-	    G_fatal_error(_("Unable to set up lat/long projection parameters"));
+        if (pj_get_kv(info_in, in_proj_info, in_unit_info) < 0)
+            G_fatal_error(_("Unable to set up lat/long projection parameters"));
 
-	G_free_key_value(in_proj_info);
-	G_free_key_value(in_unit_info);
+        G_free_key_value(in_proj_info);
+        G_free_key_value(in_unit_info);
     }
     G_free_key_value(out_proj_keys);
     G_free_key_value(out_unit_keys);
@@ -397,8 +602,8 @@
  * Use Proj to get min max bounds of region in lat long
 ********************************************************/
 void get_ll_bounds(double *w, double *e, double *s, double *n,
-		   struct Cell_head window,
-		   struct pj_info info_in, struct pj_info info_out)
+                   struct Cell_head window,
+                   struct pj_info info_in, struct pj_info info_out)
 {
     double east, west, north, south;
     double e1, w1, n1, s1;
@@ -424,68 +629,68 @@
     /* North */
     first = 0;
     for (ew = window.west; ew <= window.east; ew += ew_res) {
-	e1 = ew;
-	n1 = window.north;
-	if (pj_do_proj(&e1, &n1, &info_out, &info_in) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
-	if (!first) {
-	    north = n1;
-	    first = 1;
-	}
-	else {
-	    if (n1 > north)
-		north = n1;
-	}
+        e1 = ew;
+        n1 = window.north;
+        if (pj_do_proj(&e1, &n1, &info_out, &info_in) < 0)
+            G_fatal_error(_("Error in pj_do_proj"));
+        if (!first) {
+            north = n1;
+            first = 1;
+        }
+        else {
+            if (n1 > north)
+                north = n1;
+        }
     }
     /*South */
     first = 0;
     for (ew = window.west; ew <= window.east; ew += ew_res) {
-	e1 = ew;
-	s1 = window.south;
-	if (pj_do_proj(&e1, &s1, &info_out, &info_in) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
-	if (!first) {
-	    south = s1;
-	    first = 1;
-	}
-	else {
-	    if (s1 < south)
-		south = s1;
-	}
+        e1 = ew;
+        s1 = window.south;
+        if (pj_do_proj(&e1, &s1, &info_out, &info_in) < 0)
+            G_fatal_error(_("Error in pj_do_proj"));
+        if (!first) {
+            south = s1;
+            first = 1;
+        }
+        else {
+            if (s1 < south)
+                south = s1;
+        }
     }
 
     /*East */
     first = 0;
     for (ns = window.south; ns <= window.north; ns += ns_res) {
-	e1 = window.east;
-	n1 = ns;
-	if (pj_do_proj(&e1, &n1, &info_out, &info_in) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
-	if (!first) {
-	    east = e1;
-	    first = 1;
-	}
-	else {
-	    if (e1 > east)
-		east = e1;
-	}
+        e1 = window.east;
+        n1 = ns;
+        if (pj_do_proj(&e1, &n1, &info_out, &info_in) < 0)
+            G_fatal_error(_("Error in pj_do_proj"));
+        if (!first) {
+            east = e1;
+            first = 1;
+        }
+        else {
+            if (e1 > east)
+                east = e1;
+        }
     }
 
     /*West */
     first = 0;
     for (ns = window.south; ns <= window.north; ns += ns_res) {
-	w1 = window.west;
-	n1 = ns;
-	if (pj_do_proj(&w1, &n1, &info_out, &info_in) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
-	if (!first) {
-	    west = w1;
-	    first = 1;
-	}
-	else {
-	    if (w1 < west)
-		west = w1;
-	}
+        w1 = window.west;
+        n1 = ns;
+        if (pj_do_proj(&w1, &n1, &info_out, &info_in) < 0)
+            G_fatal_error(_("Error in pj_do_proj"));
+        if (!first) {
+            west = w1;
+            first = 1;
+        }
+        else {
+            if (w1 < west)
+                west = w1;
+        }
     }
 
     *w = west;
@@ -502,12 +707,12 @@
 ********************************************************/
 void
 check_coords(double e,
-	     double n,
-	     double *lon,
-	     double *lat,
-	     int par,
-	     struct Cell_head w,
-	     struct pj_info info_in, struct pj_info info_out)
+             double n,
+             double *lon,
+             double *lat,
+             int par,
+             struct Cell_head w,
+             struct pj_info info_in, struct pj_info info_out)
 {
     double x, y;
     int proj = 0;
@@ -516,51 +721,51 @@
     *lon = x = e;
 
     if (e < w.west) {
-	x = w.west;
-	proj = 1;
+        x = w.west;
+        proj = 1;
     }
     if (e > w.east) {
-	x = w.east;
-	proj = 1;
+        x = w.east;
+        proj = 1;
     }
     if (n < w.south) {
-	y = w.south;
-	proj = 1;
+        y = w.south;
+        proj = 1;
     }
     if (n > w.north) {
-	y = w.north;
-	proj = 1;
+        y = w.north;
+        proj = 1;
     }
 
     if (proj) {
-	/* convert original coords to ll */
-	if (pj_do_proj(&e, &n, &info_out, &info_in) < 0)
-	    G_fatal_error(_("Error in pj_do_proj1"));
+        /* convert original coords to ll */
+        if (pj_do_proj(&e, &n, &info_out, &info_in) < 0)
+            G_fatal_error(_("Error in pj_do_proj1"));
 
-	if (par == 1) {
-	    /* lines of latitude -- const. northing */
-	    /* convert correct UTM to ll */
-	    if (pj_do_proj(&x, &y, &info_out, &info_in) < 0)
-		G_fatal_error(_("Error in pj_do_proj2"));
+        if (par == 1) {
+            /* lines of latitude -- const. northing */
+            /* convert correct UTM to ll */
+            if (pj_do_proj(&x, &y, &info_out, &info_in) < 0)
+                G_fatal_error(_("Error in pj_do_proj2"));
 
-	    /* convert new ll back to coords */
-	    if (pj_do_proj(&x, &n, &info_in, &info_out) < 0)
-		G_fatal_error(_("Error in pj_do_proj3"));
-	    *lat = n;
-	    *lon = x;
-	}
-	if (par == 2) {
-	    /* lines of longitude -- const. easting */
-	    /* convert correct UTM to ll */
-	    if (pj_do_proj(&x, &y, &info_out, &info_in) < 0)
-		G_fatal_error(_("Error in pj_do_proj5"));
+            /* convert new ll back to coords */
+            if (pj_do_proj(&x, &n, &info_in, &info_out) < 0)
+                G_fatal_error(_("Error in pj_do_proj3"));
+            *lat = n;
+            *lon = x;
+        }
+        if (par == 2) {
+            /* lines of longitude -- const. easting */
+            /* convert correct UTM to ll */
+            if (pj_do_proj(&x, &y, &info_out, &info_in) < 0)
+                G_fatal_error(_("Error in pj_do_proj5"));
 
-	    /* convert new ll back to coords */
-	    if (pj_do_proj(&e, &y, &info_in, &info_out) < 0)
-		G_fatal_error(_("Error in pj_do_proj6"));
-	    *lat = y;
-	    *lon = e;
-	}
+            /* convert new ll back to coords */
+            if (pj_do_proj(&e, &y, &info_in, &info_out) < 0)
+                G_fatal_error(_("Error in pj_do_proj6"));
+            *lat = y;
+            *lon = e;
+        }
     }
 
     return;
@@ -576,32 +781,32 @@
 
     /* NE Quad or due south */
     if (rows < 0 && cols <= 0) {
-	azi = RAD_TO_DEG * atan((cols / rows));
-	if (azi < 0.)
-	    azi *= -1.;
+        azi = RAD_TO_DEG * atan((cols / rows));
+        if (azi < 0.)
+            azi *= -1.;
     }
     /* SE Quad or due east */
     if (rows >= 0 && cols < 0) {
-	azi = RAD_TO_DEG * atan((rows / cols));
-	if (azi < 0.)
-	    azi *= -1.;
-	azi = 90. + azi;
+        azi = RAD_TO_DEG * atan((rows / cols));
+        if (azi < 0.)
+            azi *= -1.;
+        azi = 90. + azi;
     }
 
     /* SW Quad or due south */
     if (rows > 0 && cols >= 0) {
-	azi = RAD_TO_DEG * atan((rows / cols));
-	if (azi < 0.)
-	    azi *= -1.;
-	azi = 270. - azi;
+        azi = RAD_TO_DEG * atan((rows / cols));
+        if (azi < 0.)
+            azi *= -1.;
+        azi = 270. - azi;
     }
 
     /* NW Quad or due south */
     if (rows <= 0 && cols > 0) {
-	azi = RAD_TO_DEG * atan((rows / cols));
-	if (azi < 0.)
-	    azi *= -1.;
-	azi = 270. + azi;
+        azi = RAD_TO_DEG * atan((rows / cols));
+        if (azi < 0.)
+            azi *= -1.;
+        azi = 270. + azi;
     }
 
     return (azi);

Modified: grass/branches/releasebranch_7_2/display/d.grid/plotborder.c
===================================================================
--- grass/branches/releasebranch_7_2/display/d.grid/plotborder.c	2016-07-14 19:18:57 UTC (rev 68963)
+++ grass/branches/releasebranch_7_2/display/d.grid/plotborder.c	2016-07-14 19:23:17 UTC (rev 68964)
@@ -15,19 +15,19 @@
     /* FIXME: pull right and bottom edges back one pixel; display lib bug? */
     row_dist = D_d_to_u_row(0.) - D_d_to_u_row(1.);
     colm_dist = D_d_to_u_col(1.) - D_d_to_u_col(0.);
-/*     window.south += row_dist;
+    /*     window.south += row_dist;
        window.east -= colm_dist;
- */
+     */
 
-    steps = grid_size / 10.;	/* tick marks number */
-    shortmark = 180.;		/* tick marks length */
+    steps = grid_size / 10.;    /* tick marks number */
+    shortmark = 180.;           /* tick marks length */
     middlemark = 90.;
     longmark = 45.;
 
 
     /* plot boundary lines: */
     /* horizontal : */
-    D_line_abs(window.west, window.south, window.east + colm_dist, window.south); /* display lib bug? */
+    D_line_abs(window.west, window.south, window.east + colm_dist, window.south);       /* display lib bug? */
     D_line_abs(window.west, window.north, window.east, window.north);
 
     /* vertical : */
@@ -37,86 +37,103 @@
 
     /* Draw ticks along top and bottom borders */
     if (window.west < east)
-	x = floor((window.west - east) / grid_size) * grid_size + east;
+        x = floor((window.west - east) / grid_size) * grid_size + east;
     else
-	x = east - ceil((east - window.west) / grid_size) * grid_size;
+        x = east - ceil((east - window.west) / grid_size) * grid_size;
 
     if (direction != DIRN_LAT) {
-	while (x <= window.east) {
-	    loop = 0;
+        while (x <= window.east) {
+            loop = 0;
 
-	    for (i = 0; i <= grid_size; i = i + steps) {
-		if (x + i < window.west || x + i > window.east) {
-		    loop++;
-		    continue;
-		}
+            for (i = 0; i <= grid_size; i = i + steps) {
+                if (x + i < window.west || x + i > window.east) {
+                    loop++;
+                    continue;
+                }
 
-		if (loop == 0) {
-		    D_line_abs(x + i,
-			      window.south + (window.north - window.south) / longmark, x + i,
-			      window.south);
-		    D_line_abs(x + i, window.north, x + i,
-			       window.north - row_dist - (window.north - window.south) / longmark);
-		}
-		if (loop == 5) {
-		    D_line_abs(x + i,
-			       window.south + (window.north - window.south) / middlemark, x + i,
-			       window.south);
-		    D_line_abs(x + i, window.north, 
-			       x + i, window.north - row_dist - (window.north - window.south) / middlemark);
-		}
-		else {
-		    D_line_abs(x + i,
-			       window.south + (window.north - window.south) / shortmark, x + i,
-			       window.south);
-		    D_line_abs(x + i, window.north,
-			       x + i, window.north - row_dist - (window.north - window.south) / shortmark);
-		}
-		loop++;
-	    }
-	    x += grid_size;
-	}
+                if (loop == 0) {
+                    D_line_abs(x + i,
+                               window.south + (window.north -
+                                               window.south) / longmark,
+                               x + i, window.south);
+                    D_line_abs(x + i, window.north, x + i,
+                               window.north - row_dist - (window.north -
+                                                          window.south) /
+                               longmark);
+                }
+                if (loop == 5) {
+                    D_line_abs(x + i,
+                               window.south + (window.north -
+                                               window.south) / middlemark,
+                               x + i, window.south);
+                    D_line_abs(x + i, window.north, x + i,
+                               window.north - row_dist - (window.north -
+                                                          window.south) /
+                               middlemark);
+                }
+                else {
+                    D_line_abs(x + i,
+                               window.south + (window.north -
+                                               window.south) / shortmark,
+                               x + i, window.south);
+                    D_line_abs(x + i, window.north, x + i,
+                               window.north - row_dist - (window.north -
+                                                          window.south) /
+                               shortmark);
+                }
+                loop++;
+            }
+            x += grid_size;
+        }
     }
 
 
     /* Draw ticks along left & right borders */
     if (window.south > north)
-	y = floor((window.south - north) / grid_size) * grid_size + north;
+        y = floor((window.south - north) / grid_size) * grid_size + north;
     else
-	y = north - ceil((north - window.south) / grid_size) * grid_size;
+        y = north - ceil((north - window.south) / grid_size) * grid_size;
 
     if (direction != DIRN_LON) {
-	while (y <= window.north) {
-	    loop = 0;
+        while (y <= window.north) {
+            loop = 0;
 
-	    for (i = 0; i <= grid_size; i = i + steps) {
-		if (y + i < window.south || y + i > window.north) {
-		    loop++;
-		    continue;
-		}
+            for (i = 0; i <= grid_size; i = i + steps) {
+                if (y + i < window.south || y + i > window.north) {
+                    loop++;
+                    continue;
+                }
 
-		if (loop == 0) {
-		    D_line_abs(window.west, y + i,
-			       window.west + (window.east - window.west) / longmark, y + i);
-		    D_line_abs(window.east - (window.east - window.west) / longmark, y + i,
-			       window.east, y + i);
-		}
-		if (loop == 5) {
-		    D_line_abs(window.west, y + i,
-			       window.west + (window.east - window.west) / middlemark, y + i);
-		    D_line_abs(window.east - (window.east - window.west) / middlemark, y + i,
-			       window.east, y + i);
-		}
-		else {
-		    D_line_abs(window.west, y + i,
-			       window.west + (window.east - window.west) / shortmark, y + i);
-		    D_line_abs(window.east - (window.east - window.west) / shortmark, y + i,
-			       window.east, y + i);
-		}
-		loop++;
-	    }
-	    y += grid_size;
-	}
+                if (loop == 0) {
+                    D_line_abs(window.west, y + i,
+                               window.west + (window.east -
+                                              window.west) / longmark, y + i);
+                    D_line_abs(window.east -
+                               (window.east - window.west) / longmark, y + i,
+                               window.east, y + i);
+                }
+                if (loop == 5) {
+                    D_line_abs(window.west, y + i,
+                               window.west + (window.east -
+                                              window.west) / middlemark,
+                               y + i);
+                    D_line_abs(window.east -
+                               (window.east - window.west) / middlemark,
+                               y + i, window.east, y + i);
+                }
+                else {
+                    D_line_abs(window.west, y + i,
+                               window.west + (window.east -
+                                              window.west) / shortmark,
+                               y + i);
+                    D_line_abs(window.east -
+                               (window.east - window.west) / shortmark, y + i,
+                               window.east, y + i);
+                }
+                loop++;
+            }
+            y += grid_size;
+        }
     }
 
     return 0;



More information about the grass-commit mailing list