Browse Source

add direction= option to allow rendering only lines of latitude or longitude (merge https://trac.osgeo.org/grass/ticket/1372 from devbr6);
fix text & tick placement (https://trac.osgeo.org/grass/ticket/1442), and try to work-around missing border/grid edge


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

Hamish Bowman 11 years ago
parent
commit
279fdc855f
5 changed files with 196 additions and 125 deletions
  1. 21 8
      display/d.grid/d.grid.html
  2. 7 3
      display/d.grid/local_proto.h
  3. 25 5
      display/d.grid/main.c
  4. 69 69
      display/d.grid/plot.c
  5. 74 40
      display/d.grid/plotborder.c

+ 21 - 8
display/d.grid/d.grid.html

@@ -29,22 +29,33 @@ inside the active graphics frame.  (A command like
 entire contents of the active display frame, must be run to
 entire contents of the active display frame, must be run to
 erase previously drawn grids from the display frame.)
 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> 
-argument accepts both decimal degrees and colon separated 
+<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>
+argument accepts both decimal degrees and colon separated
 ddd:mm:ss coordinates (eg. <tt>00:30:00</tt> for half of a degree).
 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> 
+<p>
+A geographic grid cannot be drawn for a <em>latitude/longitude</em> 
 or <em>XY</em> projection.
 or <em>XY</em> projection.
-<p>Colors may be standard named GRASS colors (red, green, aqua, etc.) or
+<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.<br>
-<p>The grid drawing may be turned off by using the <em>-n</em> flag.<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 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 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>
 <h2>EXAMPLES</h2>
+
 To draw a red geographic grid with 30 minute grid spacing run 
 To draw a red geographic grid with 30 minute grid spacing run 
 either of the following:
 either of the following:
 <pre>
 <pre>
@@ -60,6 +71,7 @@ To draw a blue standard rectangular grid at a 500 (meter) spacing run the follow
 </pre>
 </pre>
 <br>
 <br>
 
 
+
 <h2>SEE ALSO</h2>
 <h2>SEE ALSO</h2>
 
 
 <em><a href="d.barscale.html">d.barscale</a></em><br>
 <em><a href="d.barscale.html">d.barscale</a></em><br>
@@ -79,4 +91,5 @@ Geogrid support: Bob Covill<br>
 Border support: Markus Neteler<br>
 Border support: Markus Neteler<br>
 Text and RGB support: Hamish Bowman<br>
 Text and RGB support: Hamish Bowman<br>
 
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>

+ 7 - 3
display/d.grid/local_proto.h

@@ -1,9 +1,13 @@
 #include <grass/gprojects.h>
 #include <grass/gprojects.h>
 
 
+#define DIRN_BOTH 0 
+#define DIRN_LAT  1
+#define DIRN_LON  2
+
 /* plot.c */
 /* 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 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 init_proj(struct pj_info *, struct pj_info *, int);
 void get_ll_bounds(double *, double *, double *, double *, struct Cell_head,
 void get_ll_bounds(double *, double *, double *, double *, struct Cell_head,
 		   struct pj_info, struct pj_info);
 		   struct pj_info, struct pj_info);
@@ -12,7 +16,7 @@ void check_coords(double, double, double *, double *, int, struct Cell_head,
 float get_heading(double, double);
 float get_heading(double, double);
 
 
 /* plotborder.c */
 /* plotborder.c */
-int plot_border(double, double, double);
+int plot_border(double, double, double, int);
 
 
 #define MARK_GRID     0
 #define MARK_GRID     0
 #define MARK_CROSS    1
 #define MARK_CROSS    1

+ 25 - 5
display/d.grid/main.c

@@ -34,9 +34,10 @@ int main(int argc, char **argv)
     int colort = 0;
     int colort = 0;
     double size = 0., gsize = 0.;	/* initialize to zero */
     double size = 0., gsize = 0.;	/* initialize to zero */
     double east, north;
     double east, north;
-    int do_text, fontsize, mark_type, line_width;
+    int do_text, fontsize, mark_type, line_width, dirn;
     struct GModule *module;
     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,
     struct Flag *noborder, *notext, *geogrid, *nogrid, *wgs84, *cross,
 	*fiducial, *dot, *align;
 	*fiducial, *dot, *align;
     struct pj_info info_in;	/* Proj structures */
     struct pj_info info_in;	/* Proj structures */
@@ -69,6 +70,16 @@ int main(int argc, char **argv)
     opt3->multiple = NO;
     opt3->multiple = NO;
     opt3->description = _("Lines of the grid pass through this coordinate");
     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 = G_define_option();
     lwidth->key = "width";
     lwidth->key = "width";
     lwidth->type = TYPE_DOUBLE;
     lwidth->type = TYPE_DOUBLE;
@@ -185,6 +196,15 @@ int main(int argc, char **argv)
     if (dot->answer)
     if (dot->answer)
 	mark_type = MARK_DOT;
 	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);
+
     if (align->answer || strcmp(opt2->answer, "0") == 0)
     if (align->answer || strcmp(opt2->answer, "0") == 0)
 	G__get_window(&wind, "", "WIND", G_mapset());
 	G__get_window(&wind, "", "WIND", G_mapset());
 
 
@@ -249,12 +269,12 @@ int main(int argc, char **argv)
 	    /* initialzie proj stuff */
 	    /* initialzie proj stuff */
 	    init_proj(&info_in, &info_out, wgs84->answer);
 	    init_proj(&info_in, &info_out, wgs84->answer);
 	    plot_geogrid(gsize, info_in, info_out, do_text, colorg, colort,
 	    plot_geogrid(gsize, info_in, info_out, do_text, colorg, colort,
-			 fontsize, mark_type, line_width);
+			 fontsize, mark_type, line_width, dirn);
 	}
 	}
 	else {
 	else {
 	    /* Do the grid plotting */
 	    /* Do the grid plotting */
 	    plot_grid(size, east, north, do_text, colorg, colort, fontsize,
 	    plot_grid(size, east, north, do_text, colorg, colort, fontsize,
-		      mark_type, line_width);
+		      mark_type, line_width, dirn);
 	}
 	}
     }
     }
 
 
@@ -264,7 +284,7 @@ int main(int argc, char **argv)
 	D_use_color(colorb);
 	D_use_color(colorb);
 
 
 	/* Do the border plotting */
 	/* Do the border plotting */
-	plot_border(size, east, north);
+	plot_border(size, east, north, dirn);
     }
     }
 
 
     D_save_command(G_recreate_command());
     D_save_command(G_recreate_command());

+ 69 - 69
display/d.grid/plot.c

@@ -11,7 +11,7 @@
 
 
 int plot_grid(double grid_size, double east, double north, int do_text,
 int plot_grid(double grid_size, double east, double north, int do_text,
 	      int gcolor, int tcolor, int fontsize, int mark_type,
 	      int gcolor, int tcolor, int fontsize, int mark_type,
-	      double line_width)
+	      double line_width, int direction)
 {
 {
     double x, y, y0;
     double x, y, y0;
     double e1, e2;
     double e1, e2;
@@ -24,9 +24,9 @@ int plot_grid(double grid_size, double east, double north, int do_text,
     /* pull right and bottom edges back one pixel; display lib bug? */
     /* 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.);
     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.);
     colm_dist = D_d_to_u_col(1.) - D_d_to_u_col(0.);
-    window.south = window.south + row_dist;
-    window.east = window.east - colm_dist;
-
+/*    window.south += row_dist;
+      window.east -= colm_dist;
+ */
 
 
     /* Draw vertical grids */
     /* Draw vertical grids */
     if (window.west > east)
     if (window.west > east)
@@ -34,36 +34,37 @@ int plot_grid(double grid_size, double east, double north, int do_text,
     else
     else
 	x = east - ceil((east - window.west) / grid_size) * grid_size;
 	x = east - ceil((east - window.west) / grid_size) * grid_size;
 
 
-    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);
+    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 */
+	    }
 
 
-	    D_text(text);
+	    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;
 	}
 	}
-	x += grid_size;
+	D_text_rotation(0.0);	    /* reset */
     }
     }
-    D_text_rotation(0.0);	/* reset */
 
 
 
 
     /* Draw horizontal grids
     /* Draw horizontal grids
@@ -80,37 +81,40 @@ int plot_grid(double grid_size, double east, double north, int do_text,
     else
     else
 	y = north - ceil((north - window.south) / grid_size) * grid_size;
 	y = north - ceil((north - window.south) / grid_size) * grid_size;
 
 
-    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 */
-	}
-
-	if (do_text) {
-	    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);
+    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 */
+	    }
 
 
-	    D_text(text);
+	    if (do_text) {
+		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);
+
+		D_text(text);
+	    }
+	    y += grid_size;
 	}
 	}
-	y += grid_size;
     }
     }
 
 
+
     /* draw marks not grid lines */
     /* draw marks not grid lines */
     if (mark_type != MARK_GRID) {
     if (mark_type != MARK_GRID) {
 	/* reset x and y */
 	/* reset x and y */
@@ -145,7 +149,7 @@ int plot_grid(double grid_size, double east, double north, int do_text,
 
 
 int plot_geogrid(double size, struct pj_info info_in, struct pj_info info_out,
 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 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 g;
     double e1, e2, n1, n2;
     double e1, e2, n1, n2;
@@ -183,7 +187,7 @@ int plot_geogrid(double size, struct pj_info info_in, struct pj_info info_out,
     e1 = east;
     e1 = east;
     for (j = 0; g >= south; j++, g -= size) {
     for (j = 0; g >= south; j++, g -= size) {
 	start_coord = -9999.;
 	start_coord = -9999.;
-	if (g == north || g == south)
+	if (g == north || g == south || direction == DIRN_LON)
 	    continue;
 	    continue;
 
 
 	/* Set grid color */
 	/* Set grid color */
@@ -238,7 +242,7 @@ int plot_geogrid(double size, struct pj_info info_in, struct pj_info info_out,
     for (j = 0; g > west; j++, g -= size) {
     for (j = 0; g > west; j++, g -= size) {
 	start_coord = -9999.;
 	start_coord = -9999.;
 	extra_y_off = 0.0;
 	extra_y_off = 0.0;
-	if (g == east || g == west)
+	if (g == east || g == west || direction == DIRN_LAT)
 	    continue;
 	    continue;
 
 
 	/* Set grid color */
 	/* Set grid color */
@@ -354,7 +358,7 @@ void init_proj(struct pj_info *info_in, struct pj_info *info_out, int wgs84)
     }
     }
     else {
     else {
 	struct Key_Value *in_proj_info, *in_unit_info;
 	struct Key_Value *in_proj_info, *in_unit_info;
-	char buff[100], dum[100];
+	char buff[256], dum[256];
 
 
 	in_proj_info = G_create_key_value();
 	in_proj_info = G_create_key_value();
 	in_unit_info = G_create_key_value();
 	in_unit_info = G_create_key_value();
@@ -392,13 +396,9 @@ void init_proj(struct pj_info *info_in, struct pj_info *info_out, int wgs84)
 /******************************************************
 /******************************************************
  * Use Proj to get min max bounds of region in lat long
  * 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)
+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)
 {
 {
     double east, west, north, south;
     double east, west, north, south;
     double e1, w1, n1, s1;
     double e1, w1, n1, s1;

+ 74 - 40
display/d.grid/plotborder.c

@@ -1,8 +1,9 @@
 #include <math.h>
 #include <math.h>
 #include <grass/gis.h>
 #include <grass/gis.h>
 #include <grass/display.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;
     double x, y;
     struct Cell_head window;
     struct Cell_head window;
@@ -11,78 +12,111 @@ int plot_border(double grid_size, double east, double north)
 
 
     G_get_set_window(&window);
     G_get_set_window(&window);
 
 
-    /* pull right and bottom edges back one pixel; display lib bug? */
+    /* 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.);
     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.);
     colm_dist = D_d_to_u_col(1.) - D_d_to_u_col(0.);
-    window.south = window.south + row_dist;
-    window.east = window.east - colm_dist;
+/*     window.south += row_dist;
+       window.east -= colm_dist;
+ */
 
 
     steps = grid_size / 10.;	/* tick marks number */
     steps = grid_size / 10.;	/* tick marks number */
     shortmark = 180.;		/* tick marks length */
     shortmark = 180.;		/* tick marks length */
     middlemark = 90.;
     middlemark = 90.;
     longmark = 45.;
     longmark = 45.;
 
 
-    /* plot boundary lines: */
 
 
+    /* plot boundary lines: */
     /* horizontal : */
     /* horizontal : */
-    D_line_abs(window.west, window.south, window.east, window.south);
+    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);
     D_line_abs(window.west, window.north, window.east, window.north);
 
 
     /* vertical : */
     /* vertical : */
     D_line_abs(window.west, window.south, window.west, window.north);
     D_line_abs(window.west, window.south, window.west, window.north);
     D_line_abs(window.east, window.south, window.east, window.north);
     D_line_abs(window.east, window.south, window.east, window.north);
 
 
-    /* Draw vertical border marks */
+
+    /* Draw ticks along top and bottom borders */
     if (window.west < east)
     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
     else
 	x = east - ceil((east - window.west) / grid_size) * grid_size;
 	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) {
-		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 - (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 - (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 - (window.north - window.south) / shortmark);
+    if (direction != DIRN_LAT) {
+	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;
+		}
+
+		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++;
 	    }
 	    }
-	    loop++;
+	    x += grid_size;
 	}
 	}
-	x += grid_size;
     }
     }
 
 
-    /* Draw horizontal border marks */
 
 
+    /* Draw ticks along left & right borders */
     if (window.south > north)
     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
     else
 	y = north - ceil((north - window.south) / grid_size) * grid_size;
 	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) {
-		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);
+    if (direction != DIRN_LON) {
+	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;
+		}
+
+		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++;
 	    }
 	    }
-	    loop++;
+	    y += grid_size;
 	}
 	}
-	y += grid_size;
     }
     }
 
 
     return 0;
     return 0;