[GRASS-SVN] r57714 - grass/trunk/display/d.grid
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Sep 16 19:07:29 PDT 2013
Author: hamish
Date: 2013-09-16 19:07:28 -0700 (Mon, 16 Sep 2013)
New Revision: 57714
Modified:
grass/trunk/display/d.grid/d.grid.html
grass/trunk/display/d.grid/local_proto.h
grass/trunk/display/d.grid/main.c
grass/trunk/display/d.grid/plot.c
grass/trunk/display/d.grid/plotborder.c
Log:
add direction= option to allow rendering only lines of latitude or longitude (merge #1372 from devbr6);
fix text & tick placement (#1442), and try to work-around missing border/grid edge
Modified: grass/trunk/display/d.grid/d.grid.html
===================================================================
--- grass/trunk/display/d.grid/d.grid.html 2013-09-17 00:09:05 UTC (rev 57713)
+++ grass/trunk/display/d.grid/d.grid.html 2013-09-17 02:07:28 UTC (rev 57714)
@@ -29,22 +29,33 @@
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>
-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).
-<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.
-<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>
-<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 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>
@@ -60,6 +71,7 @@
</pre>
<br>
+
<h2>SEE ALSO</h2>
<em><a href="d.barscale.html">d.barscale</a></em><br>
@@ -79,4 +91,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/trunk/display/d.grid/local_proto.h
===================================================================
--- grass/trunk/display/d.grid/local_proto.h 2013-09-17 00:09:05 UTC (rev 57713)
+++ grass/trunk/display/d.grid/local_proto.h 2013-09-17 02:07:28 UTC (rev 57714)
@@ -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/trunk/display/d.grid/main.c
===================================================================
--- grass/trunk/display/d.grid/main.c 2013-09-17 00:09:05 UTC (rev 57713)
+++ grass/trunk/display/d.grid/main.c 2013-09-17 02:07:28 UTC (rev 57714)
@@ -34,9 +34,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, *align;
struct pj_info info_in; /* Proj structures */
@@ -69,6 +70,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;
@@ -185,6 +196,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);
+
if (align->answer || strcmp(opt2->answer, "0") == 0)
G__get_window(&wind, "", "WIND", G_mapset());
@@ -249,12 +269,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);
}
}
@@ -264,7 +284,7 @@
D_use_color(colorb);
/* Do the border plotting */
- plot_border(size, east, north);
+ plot_border(size, east, north, dirn);
}
D_save_command(G_recreate_command());
Modified: grass/trunk/display/d.grid/plot.c
===================================================================
--- grass/trunk/display/d.grid/plot.c 2013-09-17 00:09:05 UTC (rev 57713)
+++ grass/trunk/display/d.grid/plot.c 2013-09-17 02:07:28 UTC (rev 57714)
@@ -11,7 +11,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;
@@ -24,46 +24,47 @@
/* 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 = window.south + row_dist;
- window.east = 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;
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_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 (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);
- 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));
- /* 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);
+ D_text(text);
+ }
+ x += grid_size;
}
- x += grid_size;
+ D_text_rotation(0.0); /* reset */
}
- D_text_rotation(0.0); /* reset */
/* Draw horizontal grids
@@ -80,37 +81,40 @@
else
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 (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 */
+ }
- if (do_text) {
- D_use_color(tcolor);
- G_format_northing(y, text, G_projection());
- D_text_size(fontsize, fontsize);
+ 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);
+ /* 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);
+ D_text(text);
+ }
+ y += grid_size;
}
- y += grid_size;
}
+
/* draw marks not grid lines */
if (mark_type != MARK_GRID) {
/* reset x and y */
@@ -145,7 +149,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;
@@ -183,7 +187,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 */
@@ -238,7 +242,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 */
@@ -354,7 +358,7 @@
}
else {
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_unit_info = G_create_key_value();
@@ -392,13 +396,9 @@
/******************************************************
* 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 e1, w1, n1, s1;
Modified: grass/trunk/display/d.grid/plotborder.c
===================================================================
--- grass/trunk/display/d.grid/plotborder.c 2013-09-17 00:09:05 UTC (rev 57713)
+++ grass/trunk/display/d.grid/plotborder.c 2013-09-17 02:07:28 UTC (rev 57714)
@@ -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;
@@ -11,78 +12,111 @@
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.);
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 */
shortmark = 180.; /* tick marks length */
middlemark = 90.;
longmark = 45.;
+
/* plot boundary lines: */
-
/* 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);
/* vertical : */
D_line_abs(window.west, window.south, window.west, 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)
x = floor((window.west - east) / grid_size) * grid_size + east;
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) {
- 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 (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++;
}
- 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);
- }
- loop++;
+ x += grid_size;
}
- x += grid_size;
}
- /* Draw horizontal border marks */
+ /* Draw ticks along left & right borders */
if (window.south > north)
y = floor((window.south - north) / grid_size) * grid_size + north;
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) {
- 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 (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++;
}
- 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;
}
- y += grid_size;
}
return 0;
More information about the grass-commit
mailing list