[GRASS-SVN] r60102 - grass/trunk/display/d.legend
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon May 5 02:43:33 PDT 2014
Author: hamish
Date: 2014-05-05 02:43:33 -0700 (Mon, 05 May 2014)
New Revision: 60102
Modified:
grass/trunk/display/d.legend/Makefile
grass/trunk/display/d.legend/d.legend.html
grass/trunk/display/d.legend/get_stats.c
grass/trunk/display/d.legend/histogram.c
grass/trunk/display/d.legend/local_proto.h
grass/trunk/display/d.legend/main.c
Log:
add support for 3D raster map legends (#2083, thanks Vaclav)
Modified: grass/trunk/display/d.legend/Makefile
===================================================================
--- grass/trunk/display/d.legend/Makefile 2014-05-05 09:06:44 UTC (rev 60101)
+++ grass/trunk/display/d.legend/Makefile 2014-05-05 09:43:33 UTC (rev 60102)
@@ -2,8 +2,8 @@
PGM = d.legend
-LIBES = $(DISPLAYLIB) $(RASTERLIB) $(GISLIB) $(MATHLIB)
-DEPENDENCIES = $(DISPLAYDEP) $(RASTERDEP) $(GISDEP)
+LIBES = $(DISPLAYLIB) $(RASTERLIB) $(RASTER3DLIB) $(GISLIB) $(MATHLIB)
+DEPENDENCIES = $(DISPLAYDEP) $(RASTERDEP) $(RASTER3DDEP) $(GISDEP)
include $(MODULE_TOPDIR)/include/Make/Module.make
Modified: grass/trunk/display/d.legend/d.legend.html
===================================================================
--- grass/trunk/display/d.legend/d.legend.html 2014-05-05 09:06:44 UTC (rev 60101)
+++ grass/trunk/display/d.legend/d.legend.html 2014-05-05 09:43:33 UTC (rev 60102)
@@ -1,7 +1,7 @@
<h2>DESCRIPTION</h2>
-<em>d.legend</em> displays a legend for a user-specified
-raster map layer in the active frame on the graphics monitor.
+<em>d.legend</em> displays a legend for a user-specified raster map or
+3D raster map layer in the active frame on the graphics monitor.
<p>
The legend's default size is based on the dimensions of the
active frame, specifically its height. <em>d.legend</em> will only
@@ -65,10 +65,11 @@
output with a meaningful number of significant digits. For very small values,
numbers will be expressed in scientific notation, e.g. "1.7e-9".
<p>
-Note that old scripts which relied on setting <b>lines</b> greater than the
-number of categories to scale the legend may no longer produce the desired
-output, although the auto-scaling should still produce something that looks
-good in this case.
+When the <b>-d</b> flag is used to display a histogram distribution along
+side the smoothed gradient legend, note that the statistics are calculated
+on the <i>current computational region</i> settings set by <em>g.region</em>.
+The default <b>range</b> however covers the entire natural bounds of the input map.
+If the histogram appears empty, check your region settings.
<h2>SEE ALSO</h2>
@@ -76,14 +77,15 @@
<em>
<a href="d.barscale.html">d.barscale</a>,
<a href="d.colortable.html">d.colortable</a>,
-<a href="d.erase.html">d.erase</a>,
<a href="d.font.html">d.font</a>,
<a href="d.grid.html">d.grid</a>,
<a href="d.rast.html">d.rast</a>,
<a href="d.rast.leg.html">d.rast.leg</a>,
<a href="d.text.html">d.text</a>,
<a href="d.vect.thematic.html">d.vect.thematic</a>,
-<a href="r.reclass.html">r.reclass</a>
+<a href="r.reclass.html">r.reclass</a>,
+<a href="r.stats.html">r.stats</a>,
+<a href="r3.stats.html">r3.stats</a>
</em>
Modified: grass/trunk/display/d.legend/get_stats.c
===================================================================
--- grass/trunk/display/d.legend/get_stats.c 2014-05-05 09:06:44 UTC (rev 60101)
+++ grass/trunk/display/d.legend/get_stats.c 2014-05-05 09:43:33 UTC (rev 60102)
@@ -1,6 +1,4 @@
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
#include <grass/gis.h>
#include <grass/raster.h>
@@ -8,15 +6,20 @@
#include "local_proto.h"
-void run_stats(const char *mapname, int nsteps, const char *tempfile)
+void run_stats(const char *mapname, int nsteps, const char *tempfile,
+ int map_type)
{
char buf[32];
const char *argv[12];
int argc = 0;
- argv[argc++] = "r.stats";
+ if (map_type == MAP_TYPE_RASTER2D) {
+ argv[argc++] = "r.stats";
+ argv[argc++] = "-r";
+ }
+ else
+ argv[argc++] = "r3.stats";
- argv[argc++] = "-r";
argv[argc++] = "-c";
argv[argc++] = mapname;
@@ -35,7 +38,8 @@
}
/* linked list of stats */
-void get_stats(const char *mapname, struct stat_list *dist_stats, int nsteps)
+void get_stats(const char *mapname, struct stat_list *dist_stats, int nsteps,
+ int map_type)
{
char buf[1024]; /* input buffer for reading stats */
int done = FALSE;
@@ -59,7 +63,7 @@
G_fatal_error("Can't read frange file");
}
*/
- run_stats(mapname, nsteps, tempfile);
+ run_stats(mapname, nsteps, tempfile, map_type);
/* open temp file and read the stats into a linked list */
fd = fopen(tempfile, "r");
Modified: grass/trunk/display/d.legend/histogram.c
===================================================================
--- grass/trunk/display/d.legend/histogram.c 2014-05-05 09:06:44 UTC (rev 60101)
+++ grass/trunk/display/d.legend/histogram.c 2014-05-05 09:43:33 UTC (rev 60102)
@@ -12,7 +12,8 @@
#include "local_proto.h"
void draw_histogram(const char *map_name, int x0, int y0, int width,
- int height, int color, int flip, int horiz)
+ int height, int color, int flip, int horiz,
+ int map_type)
{
int i, nsteps;
long cell_count;
@@ -30,7 +31,7 @@
}
/* get the distribution statistics */
- get_stats(map_name, &dist_stats, nsteps);
+ get_stats(map_name, &dist_stats, nsteps, map_type);
width_mult = max_width / dist_stats.maxstat;
@@ -38,6 +39,7 @@
D_begin();
ptr = dist_stats.ptr;
+
for (i = dist_stats.mincat; i <= dist_stats.maxcat; i++) {
if (!ptr)
break;
@@ -84,7 +86,6 @@
D_cont_rel(-dx, 0);
}
-
}
D_close();
Modified: grass/trunk/display/d.legend/local_proto.h
===================================================================
--- grass/trunk/display/d.legend/local_proto.h 2014-05-05 09:06:44 UTC (rev 60101)
+++ grass/trunk/display/d.legend/local_proto.h 2014-05-05 09:43:33 UTC (rev 60102)
@@ -1,3 +1,10 @@
+#define MAP_TYPE_RASTER2D 1
+#define MAP_TYPE_RASTER3D 2
+/* possibles for the future:
+#define MAP_TYPE_VECTOR 3
+#define MAP_TYPE_RULES 4
+*/
+
struct stat_node
{
long int cat; /* cell-file category value */
@@ -20,8 +27,8 @@
/* histogram.c */
-void draw_histogram(const char *, int, int, int, int, int, int, int);
+void draw_histogram(const char *, int, int, int, int, int, int, int, int);
/* get_stats.c */
-void get_stats(const char *, struct stat_list *, int);
-void run_stats(const char *, int, const char *);
+void get_stats(const char *, struct stat_list *, int, int);
+void run_stats(const char *, int, const char *, int);
Modified: grass/trunk/display/d.legend/main.c
===================================================================
--- grass/trunk/display/d.legend/main.c 2014-05-05 09:06:44 UTC (rev 60101)
+++ grass/trunk/display/d.legend/main.c 2014-05-05 09:43:33 UTC (rev 60102)
@@ -29,6 +29,7 @@
#include <math.h>
#include <grass/gis.h>
#include <grass/raster.h>
+#include <grass/raster3d.h>
#include <grass/display.h>
#include <grass/glocale.h>
#include "local_proto.h"
@@ -38,6 +39,7 @@
{
char buff[512];
char *map_name;
+ int maptype;
int black;
int cats_num;
int color;
@@ -57,13 +59,13 @@
struct Categories cats;
struct Colors colors;
struct GModule *module;
- struct Option *opt_input, *opt_color, *opt_lines, *opt_thin,
- *opt_labelnum, *opt_at, *opt_use, *opt_range,
+ struct Option *opt_rast2d, *opt_rast3d, *opt_color, *opt_lines,
+ *opt_thin, *opt_labelnum, *opt_at, *opt_use, *opt_range,
*opt_font, *opt_path, *opt_charset, *opt_fontsize;
struct Flag *hidestr, *hidenum, *hidenodata, *smooth, *flipit, *histo;
struct Range range;
struct FPRange fprange;
- CELL min_ind, max_ind, null_cell;
+ CELL min_ind, max_ind;
DCELL dmin, dmax, val;
CELL min_colr, max_colr;
DCELL min_dcolr, max_dcolr;
@@ -89,12 +91,15 @@
_("Displays a legend for a raster map in the active frame "
"of the graphics monitor.");
- opt_input = G_define_standard_option(G_OPT_R_MAP);
- opt_input->description = _("Name of raster map");
+ opt_rast2d = G_define_standard_option(G_OPT_R_MAP);
+ opt_rast2d->key = "rast";
+ opt_rast2d->required = NO;
+ opt_rast2d->guisection = _("Input");
- opt_color = G_define_standard_option(G_OPT_C_FG);
- opt_color->label = _("Text color");
- opt_color->guisection = _("Font settings");
+ opt_rast3d = G_define_standard_option(G_OPT_R3_MAP);
+ opt_rast3d->key = "rast3d";
+ opt_rast3d->required = NO;
+ opt_rast3d->guisection = _("Input");
opt_lines = G_define_option();
opt_lines->key = "lines";
@@ -154,6 +159,10 @@
_("Use a subset of the map range for the legend (min,max)");
opt_range->guisection = _("Subset");
+ opt_color = G_define_standard_option(G_OPT_C_FG);
+ opt_color->label = _("Text color");
+ opt_color->guisection = _("Font settings");
+
opt_font = G_define_option();
opt_font->key = "font";
opt_font->type = TYPE_STRING;
@@ -213,15 +222,26 @@
histo = G_define_flag();
histo->key = 'd';
histo->description = _("Add histogram to smoothed legend");
- histo->guisection = _("Advanced");
+ histo->guisection = _("Gradient");
/* Check command line */
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+ /* FIXME: add GUI launching logic to G_parser() call */
+ if ((opt_rast2d->answer && opt_rast3d->answer) ||
+ !(opt_rast2d->answer || opt_rast3d->answer))
+ G_fatal_error(_("Please specify a single map name. To launch GUI use d.legend --ui."));
- map_name = opt_input->answer;
+ if (opt_rast2d->answer) {
+ map_name = opt_rast2d->answer;
+ maptype = MAP_TYPE_RASTER2D;
+ }
+ else {
+ map_name = opt_rast3d->answer;
+ maptype = MAP_TYPE_RASTER3D;
+ }
hide_catstr = hidestr->answer; /* note hide_catstr gets changed and re-read below */
hide_catnum = hidenum->answer;
@@ -274,22 +294,29 @@
}
}
+ if (maptype == MAP_TYPE_RASTER2D) {
+ if (Rast_read_colors(map_name, "", &colors) == -1)
+ G_fatal_error(_("Color file for <%s> not available"), map_name);
- if (Rast_read_colors(map_name, "", &colors) == -1)
- G_fatal_error(_("Color file for <%s> not available"), map_name);
+ fp = Rast_map_is_fp(map_name, "");
+
+ Rast_read_cats(map_name, "", &cats);
+ }
+ else {
+ if (Rast3d_read_colors(map_name, "", &colors) == -1)
+ G_fatal_error(_("Color file for <%s> not available"), map_name);
- fp = Rast_map_is_fp(map_name, "");
+ fp = TRUE; /* currently raster 3D is always floating point */
+
+ Rast3d_read_cats(map_name, "", &cats);
+ }
+
if (fp && !use_catlist) {
do_smooth = TRUE;
/* fprintf(stderr, "FP map found - switching gradient legend on\n"); */
flip = !flip;
}
- if (Rast_read_cats(map_name, "", &cats) == -1)
- G_warning(_("Category file for <%s> not available"), map_name);
-
- Rast_set_c_null_value(&null_cell, 1);
-
if (D_open_driver() != 0)
G_fatal_error(_("No graphics device selected. "
"Use d.mon to select graphics device."));
@@ -334,7 +361,7 @@
x0 = l + (int)((r - l) * X0 / 100.);
x1 = l + (int)((r - l) * X1 / 100.);
- y0 = t + (int)((b - t) * (100. - Y0) / 100.); /* make lower left the origin */
+ y0 = t + (int)((b - t) * (100. - Y0) / 100.); /* make lower left the origin */
y1 = t + (int)((b - t) * (100. - Y1) / 100.);
if (y0 > y1) { /* allow for variety in order of corner */
@@ -532,13 +559,19 @@
sprintf(DispFormat, "%%2d");
}
}
- else { /* is fp */
- if (Rast_read_fp_range(map_name, "", &fprange) == -1)
- G_fatal_error(_("Range information for <%s> not available"),
- map_name);
+ else { /* is fp */
+ if (maptype == MAP_TYPE_RASTER2D) {
+ if (Rast_read_fp_range(map_name, "", &fprange) == -1)
+ G_fatal_error(_("Range information for <%s> not available"),
+ map_name);
+ }
+ else {
+ if (Rast3d_read_range(map_name, "", &fprange) == -1)
+ G_fatal_error(_("Range information for <%s> not available"),
+ map_name);
+ }
Rast_get_fp_range_min_max(&fprange, &dmin, &dmax);
-
Rast_get_d_color_range(&min_dcolr, &max_dcolr, &colors);
if (UserRange) {
@@ -776,7 +809,7 @@
G_warning(_("Histogram constrained by range not yet implemented"));
else
draw_histogram(map_name, x0, y0, wleg, lleg, color, flip,
- horiz);
+ horiz, maptype);
}
}
More information about the grass-commit
mailing list