[GRASS-SVN] r69310 - in grass/branches/releasebranch_7_2: display/d.legend.vect display/d.vect display/d.vect.thematic gui/wxpython/core gui/wxpython/lmgr
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 30 20:34:50 PDT 2016
Author: annakrat
Date: 2016-08-30 20:34:50 -0700 (Tue, 30 Aug 2016)
New Revision: 69310
Added:
grass/branches/releasebranch_7_2/display/d.vect.thematic/display.c
grass/branches/releasebranch_7_2/display/d.vect.thematic/legend.c
Modified:
grass/branches/releasebranch_7_2/display/d.legend.vect/d.legend.vect.html
grass/branches/releasebranch_7_2/display/d.vect.thematic/Makefile
grass/branches/releasebranch_7_2/display/d.vect.thematic/local_proto.h
grass/branches/releasebranch_7_2/display/d.vect.thematic/main.c
grass/branches/releasebranch_7_2/display/d.vect/main.c
grass/branches/releasebranch_7_2/gui/wxpython/core/render.py
grass/branches/releasebranch_7_2/gui/wxpython/lmgr/layertree.py
Log:
d.vect.thematic: merge recent changes by Adam Laza from trunk
Modified: grass/branches/releasebranch_7_2/display/d.legend.vect/d.legend.vect.html
===================================================================
--- grass/branches/releasebranch_7_2/display/d.legend.vect/d.legend.vect.html 2016-08-31 03:25:43 UTC (rev 69309)
+++ grass/branches/releasebranch_7_2/display/d.legend.vect/d.legend.vect.html 2016-08-31 03:34:50 UTC (rev 69310)
@@ -9,7 +9,8 @@
border color and border width (<b>border_color</b> and <b>border_width</b>).
Parameter <b>symbol_size</b> defines the size of line and area symbols.
The size of point symbols is based on currently set symbology of vector maps using
-<em><a href="d.vect.html">d.vect</a></em>.
+<em><a href="d.vect.html">d.vect</a></em> or
+<em><a href="d.vect.thematic.html">d.vect.thematic</a></em>.
<p>Module <em>d.vect.legend</em> supports subtitles (see section Notes).
Their font and font size can be set using parameters <b>sub_font</b>
and <b>sub_fontsize</b>.
@@ -17,15 +18,19 @@
<h3>Changing legend symbols and labels</h3>
Symbols for vector areas and lines, and labels for individual vector labels
can be changed in the symbology setting of each vector map in
-<em><a href="d.vect.html">d.vect</a></em> module (in Legend tab). Use its parameters
+<em><a href="d.vect.html">d.vect</a></em> or
+<em><a href="d.vect.thematic.html">d.vect.thematic</a></em>
+module (in Legend tab). Use its parameters
<b>icon_area</b> and <b>icon_line</b> to pick from available symbols.
By using parameter <b>legend_label</b> of <em>d.vect</em> module, users can change
the default label, which is the map name.
<h3>Modifying the order of legend entries and omitting certain vector maps
from legend</h3>
-Module <em><a href="d.vect.html">d.vect</a></em> has a flag <b>-l</b>
-which when used removes the particular vector from vector legend.
+Modules <em><a href="d.vect.html">d.vect</a></em> and
+<em><a href="d.vect.thematic.html">d.vect.thematic</a></em>
+have a flag <b>-s</b>
+which removes the particular vector or thematic vector from vector legend.
<p>The order of entries is defined by the order in Layer Manager (if used
in GRASS GIS GUI). If that's not desired, one can export the legend file
into a text file using parameter <b>output</b>, change the order of entries
@@ -82,6 +87,7 @@
<em>
<a href="d.vect.html">d.vect</a>,
+<a href="d.vect.thematic.html">d.vect.thematic</a>,
<a href="d.legend.html">d.legend</a>
</em>
Modified: grass/branches/releasebranch_7_2/display/d.vect/main.c
===================================================================
--- grass/branches/releasebranch_7_2/display/d.vect/main.c 2016-08-31 03:25:43 UTC (rev 69309)
+++ grass/branches/releasebranch_7_2/display/d.vect/main.c 2016-08-31 03:34:50 UTC (rev 69310)
@@ -325,8 +325,8 @@
sqrt_flag->guisection = _("Symbols");
legend_flag = G_define_flag();
- legend_flag->key = 'l';
- legend_flag->label = _("Do not add this layer to vector legend");
+ legend_flag->key = 's';
+ legend_flag->label = _("Do not show this layer in vector legend");
legend_flag->guisection = _("Legend");
/* Check command line */
Modified: grass/branches/releasebranch_7_2/display/d.vect.thematic/Makefile
===================================================================
--- grass/branches/releasebranch_7_2/display/d.vect.thematic/Makefile 2016-08-31 03:25:43 UTC (rev 69309)
+++ grass/branches/releasebranch_7_2/display/d.vect.thematic/Makefile 2016-08-31 03:34:50 UTC (rev 69310)
@@ -3,8 +3,8 @@
PGM = d.vect.thematic
-LIBES = $(ARRAYSTATSLIB) $(DISPLAYLIB) $(VECTORLIB) $(DBMILIB) $(GISLIB)
-DEPENDENCIES = $(ARRAYSTATSDEP) $(DISPLAYDEP) $(VECTORDEP) $(DBMIDEP) $(GISDEP)
+LIBES = $(ARRAYSTATSLIB) $(DISPLAYLIB) $(VECTORLIB) $(DBMILIB) $(GISLIB) $(SYMBLIB)
+DEPENDENCIES = $(ARRAYSTATSDEP) $(DISPLAYDEP) $(VECTORDEP) $(DBMIDEP) $(GISDEP) $(SYMBDEP)
EXTRA_INC = $(VECT_INC)
EXTRA_CFLAGS = $(VECT_CFLAGS)
Copied: grass/branches/releasebranch_7_2/display/d.vect.thematic/display.c (from rev 69134, grass/trunk/display/d.vect.thematic/display.c)
===================================================================
--- grass/branches/releasebranch_7_2/display/d.vect.thematic/display.c (rev 0)
+++ grass/branches/releasebranch_7_2/display/d.vect.thematic/display.c 2016-08-31 03:34:50 UTC (rev 69310)
@@ -0,0 +1,241 @@
+/* Author: Adam Laza, GSoC 2016
+ * based on d.vect.thematic/area.c
+ *
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/symbol.h>
+#include <grass/vector.h>
+#include <grass/display.h>
+#include <grass/colors.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+#include "plot.h"
+#include "local_proto.h"
+
+int display_lines(struct Map_info *Map, struct cat_list *Clist,
+ int chcat, const char *symbol_name, double size,
+ int default_width, dbCatValArray * cvarr, double *breaks,
+ int nbreaks, const struct color_rgb *colors, const struct
+ color_rgb *bcolor)
+{
+ int ltype, line, nlines;
+ struct line_pnts *Points;
+ struct line_cats *Cats;
+
+ int n_points, n_lines, n_centroids, n_boundaries, n_faces;
+ RGBA_Color *primary_color, *secondary_color;
+ SYMBOL *Symb;
+
+ Symb = NULL;
+
+ double breakval = 0.0;
+ int cat;
+ dbCatVal *cv = NULL;
+ int i;
+
+ primary_color = G_malloc(sizeof(RGBA_Color));
+ primary_color->a = RGBA_COLOR_OPAQUE;
+ secondary_color = G_malloc(sizeof(RGBA_Color));
+ secondary_color->a = RGBA_COLOR_OPAQUE;
+
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+
+ /* dynamic symbols for points */
+ Symb = S_read(symbol_name);
+ if (!Symb)
+ G_warning(_("Unable to read symbol <%s>, unable to display points"),
+ symbol_name);
+ else
+ S_stroke(Symb, size, 0.0, 0);
+
+ Vect_rewind(Map);
+
+ nlines = -1;
+ line = 0;
+ n_points = n_lines = 0;
+ n_centroids = n_boundaries = 0;
+ n_faces = 0;
+ while (TRUE) {
+ line++;
+
+ if (nlines > -1) {
+ if (line > nlines)
+ break;
+ ltype = Vect_read_line(Map, Points, Cats, line);
+ }
+ else {
+ ltype = Vect_read_next_line(Map, Points, Cats);
+
+ if (ltype == -1) {
+ G_fatal_error(_("Unable to read vector map"));
+ }
+ else if ((ltype == -2)) { /* EOF */
+ break;
+ }
+ }
+
+ cat = *Cats->cat;
+ if (cat >= 0) {
+ G_debug(3, "display line %d, cat %d", line, cat);
+ /* Get value of data for this area */
+ if (db_CatValArray_get_value(cvarr, cat, &cv) != DB_OK) {
+ G_debug(3, "No value found for cat %i", cat);
+ }
+ else {
+ db_CatValArray_get_value(cvarr, cat, &cv);
+ breakval = (cvarr->ctype == 2 ? cv->val.i : cv->val.d);
+ }
+ }
+
+ /* find out into which class breakval falls */
+ i = 0;
+ while (breakval > breaks[i] && i < nbreaks)
+ i++;
+ primary_color->r = colors[i].r;
+ primary_color->g = colors[i].g;
+ primary_color->b = colors[i].b;
+
+ if (bcolor !=NULL) {
+ secondary_color->r = bcolor->r;
+ secondary_color->g = bcolor->g;
+ secondary_color->b = bcolor->b;
+ }
+ else
+ secondary_color->a = 0;
+
+ draw_line(ltype, line, Points, Cats, chcat, size, default_width,
+ Clist, Symb, primary_color, &n_points, &n_lines,
+ &n_centroids, &n_boundaries, &n_faces, secondary_color);
+ }
+
+ if (n_points > 0)
+ G_verbose_message(n_
+ ("%d point plotted", "%d points plotted", n_points),
+ n_points);
+ if (n_lines > 0)
+ G_verbose_message(n_("%d line plotted", "%d lines plotted", n_lines),
+ n_lines);
+ if (n_centroids > 0)
+ G_verbose_message(n_
+ ("%d centroid plotted", "%d centroids plotted",
+ n_centroids), n_centroids);
+ if (n_boundaries > 0)
+ G_verbose_message(n_
+ ("%d boundary plotted", "%d boundaries plotted",
+ n_boundaries), n_boundaries);
+ if (n_faces > 0)
+ G_verbose_message(n_("%d face plotted", "%d faces plotted", n_faces),
+ n_faces);
+
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_cats_struct(Cats);
+ G_free(primary_color);
+
+ return 0;
+}
+
+int draw_line(int ltype, int line,
+ const struct line_pnts *Points, const struct line_cats *Cats,
+ int chcat, double size, int default_width,
+ const struct cat_list *Clist, SYMBOL * Symb,
+ RGBA_Color * primary_color,
+ int *n_points, int *n_lines, int *n_centroids,
+ int *n_boundaries, int *n_faces, RGBA_Color *secondary_color)
+{
+ double var_size, rotation;
+ int i;
+ double x0, y0;
+ double *x, *y;
+ int found, cat;
+
+ rotation = 0.0;
+ var_size = size;
+ cat = -1;
+
+ if (!ltype)
+ return 0;
+
+ if (Points->n_points == 0)
+ return 0;
+
+ found = FALSE;
+ if (chcat) {
+ for (i = 0; i < Cats->n_cats; i++) {
+ if (Cats->field[i] == Clist->field &&
+ Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found)
+ return 0;
+ }
+ else if (Clist->field > 0) {
+ for (i = 0; i < Cats->n_cats; i++) {
+ if (Cats->field[i] == Clist->field) {
+ found = TRUE;
+ break;
+ }
+ }
+ /* lines with no category will be displayed */
+ if (Cats->n_cats > 0 && !found)
+ return 0;
+ }
+
+ G_debug(3, "\tdisplay feature %d, cat %d", line, cat);
+
+
+ /* enough of the prep work, lets start plotting stuff */
+ x = Points->x;
+ y = Points->y;
+
+ if ((ltype & GV_POINTS)) {
+ x0 = x[0];
+ y0 = y[0];
+
+ /* skip if the point is outside of the display window */
+ /* xy < 0 tests make it go ever-so-slightly faster */
+ if (x0 > D_get_u_east() || x0 < D_get_u_west() ||
+ y0 < D_get_u_south() || y0 > D_get_u_north())
+ return 0;
+
+ D_line_width(default_width);
+ D_symbol2(Symb, x0, y0, primary_color, secondary_color);
+ }
+ else {
+ /* Plot the lines */
+ D_line_width(default_width);
+ D_RGB_color(primary_color->r, primary_color->g, primary_color->b);
+ if (Points->n_points == 1) /* line with one coor */
+ D_polydots_abs(x, y, Points->n_points);
+ else /* use different user defined render methods */
+ D_polyline_abs(x, y, Points->n_points);
+ }
+
+ switch (ltype) {
+ case GV_POINT:
+ (*n_points)++;
+ break;
+ case GV_LINE:
+ (*n_lines)++;
+ break;
+ case GV_CENTROID:
+ (*n_centroids)++;
+ break;
+ case GV_BOUNDARY:
+ (*n_boundaries)++;
+ break;
+ case GV_FACE:
+ (*n_faces)++;
+ break;
+ default:
+ break;
+ }
+
+ return 1;
+}
Copied: grass/branches/releasebranch_7_2/display/d.vect.thematic/legend.c (from rev 69284, grass/trunk/display/d.vect.thematic/legend.c)
===================================================================
--- grass/branches/releasebranch_7_2/display/d.vect.thematic/legend.c (rev 0)
+++ grass/branches/releasebranch_7_2/display/d.vect.thematic/legend.c 2016-08-31 03:34:50 UTC (rev 69310)
@@ -0,0 +1,65 @@
+/* Author: Adam Laza, GSoC 2016
+ *
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/symbol.h>
+#include <grass/vector.h>
+#include <grass/display.h>
+#include <grass/colors.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+#include "plot.h"
+#include "local_proto.h"
+
+void write_into_legend_file(const char *legfile, const char *icon, const char *title, double stats_min, double stats_max,
+ double *breakpoints, int nbreaks, int size, struct color_rgb bcolor,
+ struct color_rgb *colors, int default_width, int* frequencies, const char *topo)
+{
+ FILE *fd;
+ int i;
+
+ if (strcmp(legfile,"stdout") == 0)
+ fd = stdout;
+ else
+ fd = fopen(legfile, "a");
+
+ /* Title */
+ fprintf(fd, "|||||%s\n", title);
+
+ /* First line */
+ if (stats_min > breakpoints[0]){
+ fprintf(fd, "< %.2f|", breakpoints[0]);
+ }
+ else{
+ fprintf(fd, "%.2f - %.2f|",stats_min, breakpoints[0]);
+ }
+ fprintf(fd, "%s|%d|%d:%d:%d|%d:%d:%d|%d|%s|%d\n",
+ icon, size, bcolor.r, bcolor.g, bcolor.b,
+ colors[0].r, colors[0].g, colors[0].b, default_width,
+ topo, frequencies[0]);
+ /* Middle lines */
+ for (i = 1; i < nbreaks; i++){
+ fprintf(fd, "%.2f - %.2f|%s|%d|%d:%d:%d|%d:%d:%d|%d|%s|%d\n",
+ breakpoints[i-1],breakpoints[i],
+ icon, size, bcolor.r, bcolor.g, bcolor.b,
+ colors[i].r, colors[i].g, colors[i].b, default_width,
+ topo, frequencies[i]);
+ }
+ /* Last one */
+ if(stats_max < breakpoints[nbreaks-1]){
+ fprintf(fd, ">%.2f|", breakpoints[nbreaks - 1]);
+ }
+ else {
+ fprintf(fd, "%.2f - %.2f|", breakpoints[nbreaks - 1], stats_max);
+ }
+ fprintf(fd, "%s|%d|%d:%d:%d|%d:%d:%d|%d|%s|%d\n",
+ icon, size, bcolor.r, bcolor.g, bcolor.b,
+ colors[nbreaks].r, colors[nbreaks].g, colors[nbreaks].b, default_width,
+ topo, frequencies[nbreaks]);
+
+ fclose(fd);
+}
Modified: grass/branches/releasebranch_7_2/display/d.vect.thematic/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_2/display/d.vect.thematic/local_proto.h 2016-08-31 03:25:43 UTC (rev 69309)
+++ grass/branches/releasebranch_7_2/display/d.vect.thematic/local_proto.h 2016-08-31 03:34:50 UTC (rev 69310)
@@ -12,3 +12,23 @@
const struct color_rgb *, int, struct Cell_head *, int);
int dcmp(const void *, const void *);
+static int cmp(const void *, const void *);
+static char *icon_files(void);
+
+/* display.c */
+int draw_line(int ltype, int line,
+ const struct line_pnts *Points, const struct line_cats *Cats,
+ int chcat, double size, int default_width,
+ const struct cat_list *Clist, SYMBOL *Symb,
+ RGBA_Color *primary_color, int *n_points, int *n_lines,
+ int *n_centroids, int *n_boundaries, int *n_faces,
+ RGBA_Color *secondary_color);
+
+int display_lines(struct Map_info *, struct cat_list *, int,
+ const char *, double, int, dbCatValArray *, double *, int,
+ const struct color_rgb *, const struct color_rgb *);
+
+/* legend.c */
+void write_into_legend_file(const char *, const char *, const char *, double, double,
+ double *, int, int, struct color_rgb,
+ struct color_rgb *, int, int*, const char *);
Modified: grass/branches/releasebranch_7_2/display/d.vect.thematic/main.c
===================================================================
--- grass/branches/releasebranch_7_2/display/d.vect.thematic/main.c 2016-08-31 03:25:43 UTC (rev 69309)
+++ grass/branches/releasebranch_7_2/display/d.vect.thematic/main.c 2016-08-31 03:34:50 UTC (rev 69310)
@@ -30,12 +30,11 @@
#include "plot.h"
#include "local_proto.h"
-
int main(int argc, char **argv)
{
int ret, level;
int i, stat = 0;
- int nclass = 0, nbreaks, *frequencies, boxsize, textsize, ypos;
+ int nclass = 0, nbreaks, *frequencies;
int chcat = 0;
int r, g, b;
int has_color = 0;
@@ -55,8 +54,13 @@
struct Option *where_opt;
struct Option *field_opt;
struct Option *legend_file_opt;
- struct Flag *legend_flag, *algoinfo_flag, *nodraw_flag;
- char *desc;
+ struct Option *icon_opt;
+ struct Option *icon_line_opt;
+ struct Option *icon_area_opt;
+ struct Option *size_opt;
+ struct Option *title_opt;
+ struct Flag *legend_flag, *algoinfo_flag, *nodraw_flag, *vlegend_flag;
+ char *desc, *deprecated;
struct cat_list *Clist;
int *cats, ncat, nrec, ctype;
@@ -69,7 +73,10 @@
struct bound_box box;
double overlap, *breakpoints, *data = NULL, class_info = 0.0;
struct GASTATS stats;
- FILE *fd;
+ int size;
+ int nfeatures;
+ char title[128];
+ char *leg_file;
/* Initialize the GIS calls */
G_gisinit(argv[0]);
@@ -143,19 +150,70 @@
bwidth_opt = G_define_option();
bwidth_opt->key = "boundary_width";
bwidth_opt->type = TYPE_INTEGER;
- bwidth_opt->answer = "0";
+ bwidth_opt->answer = "1";
bwidth_opt->guisection = _("Boundaries");
bwidth_opt->description = _("Boundary width");
- bcolor_opt = G_define_standard_option(G_OPT_C);
+ bcolor_opt = G_define_standard_option(G_OPT_CN);
bcolor_opt->key = "boundary_color";
bcolor_opt->label = _("Boundary color");
bcolor_opt->guisection = _("Boundaries");
+ /* Symbols */
+ icon_opt = G_define_option();
+ icon_opt->key = "icon";
+ icon_opt->type = TYPE_STRING;
+ icon_opt->required = NO;
+ icon_opt->multiple = NO;
+ icon_opt->guisection = _("Symbols");
+ icon_opt->answer = "basic/x";
+ /* This could also use ->gisprompt = "old,symbol,symbol" instead of ->options */
+ icon_opt->options = icon_files();
+ icon_opt->description = _("Point and centroid symbol");
+
+ size_opt = G_define_option();
+ size_opt->key = "size";
+ size_opt->type = TYPE_DOUBLE;
+ size_opt->answer = "5";
+ size_opt->guisection = _("Symbols");
+ size_opt->label = _("Symbol size");
+
+ icon_line_opt = G_define_option();
+ icon_line_opt->key = "icon_line";
+ icon_line_opt->type = TYPE_STRING;
+ icon_line_opt->required = NO;
+ icon_line_opt->multiple = NO;
+ icon_line_opt->guisection = _("Legend");
+ icon_line_opt->answer = "legend/line";
+ /* This could also use ->gisprompt = "old,symbol,symbol" instead of ->options */
+ icon_line_opt->options = icon_files();
+ icon_line_opt->description = _("Legend symbol for lines");
+
+ icon_area_opt = G_define_option();
+ icon_area_opt->key = "icon_area";
+ icon_area_opt->type = TYPE_STRING;
+ icon_area_opt->required = NO;
+ icon_area_opt->multiple = NO;
+ icon_area_opt->guisection = _("Legend");
+ icon_area_opt->answer = "legend/area";
+ /* This could also use ->gisprompt = "old,symbol,symbol" instead of ->options */
+ icon_area_opt->options = icon_files();
+ icon_area_opt->description = _("Legend symbol for areas");
+
+ title_opt = G_define_option();
+ title_opt->key = "legend_title";
+ title_opt->type = TYPE_STRING;
+ title_opt->guisection = _("Legend");
+ title_opt->description = _("Thematic map title");
+
legend_file_opt = G_define_standard_option(G_OPT_F_OUTPUT);
legend_file_opt->key = "legendfile";
- legend_file_opt->description =
- _("File in which to save d.graph instructions for legend display");
+ deprecated = NULL;
+ G_asprintf(&deprecated,
+ "[%s] %s",
+ _("DEPRECATED"),
+ _("Output legend file"));
+ legend_file_opt->description = deprecated;
legend_file_opt->required = NO;
legend_file_opt->guisection = _("Legend");
@@ -165,36 +223,63 @@
_("Create legend information and send to stdout");
legend_flag->guisection = _("Legend");
+ nodraw_flag = G_define_flag();
+ nodraw_flag->key = 'n';
+ nodraw_flag->description = _("Do not draw map, only output the legend information");
+ nodraw_flag->guisection = _("Legend");
+
algoinfo_flag = G_define_flag();
algoinfo_flag->key = 'e';
- algoinfo_flag->description =
- _("When printing legend info, include extended statistical info from classification algorithm");
+ deprecated = NULL;
+ G_asprintf(&deprecated,
+ "[%s] %s",
+ _("DEPRECATED"),
+ _("When printing legend info, include extended statistical info from classification algorithm"));
+ algoinfo_flag->description = deprecated;
algoinfo_flag->guisection = _("Legend");
+
+ vlegend_flag = G_define_flag();
+ vlegend_flag->key = 's';
+ vlegend_flag->label = _("Do not show this layer in vector legend");
+ vlegend_flag->guisection = _("Legend");
+
+ G_option_required(algo_opt, breaks_opt, NULL);
+ G_option_exclusive(algo_opt, breaks_opt, NULL);
+ G_option_requires(algo_opt, nbclass_opt, NULL);
- nodraw_flag = G_define_flag();
- nodraw_flag->key = 'n';
- nodraw_flag->description = _("Do not draw map, only output the legend");
- nodraw_flag->guisection = _("Legend");
-
/* Check command line */
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+ if (algoinfo_flag->answer)
+ G_warning(_("Flag -e is deprecated, set verbose mode with --v to get the extended statistical info."));
+
+ if (legend_file_opt->answer)
+ G_warning(_("Option legendfile is deprecated, either use flag -l "
+ "to print legend to standard output, "
+ "or set GRASS_LEGEND_FILE environment variable "
+ "(see d.legend.vect for details)."));
+
if (G_verbose() > G_verbose_std())
verbose = TRUE;
G_get_set_window(&window);
+ size = atof(size_opt->answer);
+
/* Read map options */
-
strcpy(map_name, map_opt->answer);
/* open vector */
level = Vect_open_old(&Map, map_name, "");
-
+
if (level < 2)
G_fatal_error(_("%s: You must build topology on vector map. Run v.build."),
map_name);
+ if (title_opt->answer)
+ strcpy(title, title_opt->answer);
+ else
+ strcpy(title, Map.name);
/* Check database connection and open it */
Clist = Vect_new_cat_list();
@@ -214,8 +299,6 @@
G_fatal_error(_("Unable to open database <%s>"), fi->database);
}
-
-
/*Get CatValArray needed for plotting and for legend calculations */
db_CatValArray_init(&cvarr);
nrec = db_select_CatValArray(driver, fi->table, fi->key,
@@ -400,13 +483,20 @@
/* default line width */
D_line_width(default_width);
-
+ if (Vect_get_num_primitives(&Map, GV_BOUNDARY) > 0)
stat =
dareatheme(&Map, Clist, &cvarr, breakpoints, nbreaks, colors,
has_color ? &bcolor : NULL, chcat, &window,
default_width);
+ else if ((Vect_get_num_primitives(&Map, GV_POINT) > 0) ||
+ (Vect_get_num_primitives(&Map, GV_LINE) > 0)){
+ stat = display_lines(&Map, Clist, chcat, icon_opt->answer, size,
+ default_width, &cvarr, breakpoints, nbreaks, colors,
+ has_color ? &bcolor : NULL);
+ }
+
/* reset line width: Do we need to get line width from display
* driver (not implemented)? It will help restore previous line
* width (not just 0) determined by another module (e.g.,
@@ -428,96 +518,115 @@
/*Get basic statistics about the data */
AS_basic_stats(data, nrec, &stats);
- if (legend_flag->answer) {
+ /* Print statistics */
+ G_verbose_message(_("\nTotal number of records: %.0f\n"),
+ stats.count);
+ G_verbose_message(_("Classification of %s into %i classes\n"),
+ column_opt->answer, nbreaks + 1);
+ G_verbose_message(_("Using algorithm: *** %s ***\n"),
+ algo_opt->answer);
+ G_verbose_message(_("Mean: %f\tStandard deviation = %f\n"),
+ stats.mean, stats.stdev);
+
+ if (G_strcasecmp(algo_opt->answer, "dis") == 0)
+ G_verbose_message(_("Last chi2 = %f\n"), class_info);
+ if (G_strcasecmp(algo_opt->answer, "std") == 0)
+ G_verbose_message(_("Stdev multiplied by %.4f to define step\n"),
+ class_info);
+ G_verbose_message("\n");
- if (algoinfo_flag->answer) {
-
-
- fprintf(stdout, _("\nTotal number of records: %.0f\n"),
- stats.count);
- fprintf(stdout, _("Classification of %s into %i classes\n"),
- column_opt->answer, nbreaks + 1);
- fprintf(stdout, _("Using algorithm: *** %s ***\n"),
- algo_opt->answer);
- fprintf(stdout, _("Mean: %f\tStandard deviation = %f\n"),
- stats.mean, stats.stdev);
-
- if (G_strcasecmp(algo_opt->answer, "dis") == 0)
- fprintf(stdout, _("Last chi2 = %f\n"), class_info);
- if (G_strcasecmp(algo_opt->answer, "std") == 0)
- fprintf(stdout,
- _("Stdev multiplied by %.4f to define step\n"),
- class_info);
- fprintf(stdout, "\n");
-
+ /* Print legfile to stdout */
+ if ((legend_flag->answer) ||
+ ((legend_file_opt->answer) && (strcmp(legend_file_opt->answer,"-") == 0))) {
+ while (TRUE) {
+ nfeatures = Vect_get_num_primitives(&Map, GV_POINT);
+ if (nfeatures > 0) {
+ write_into_legend_file("stdout", icon_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "point");
+ break;
+ }
+ nfeatures = Vect_get_num_primitives(&Map, GV_LINE);
+ if (nfeatures > 0) {
+ write_into_legend_file("stdout", icon_line_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "line");
+ break;
}
-
- if(stats.min > breakpoints[0]){
- fprintf(stdout, "<%f|%i|%d:%d:%d\n",
- breakpoints[0], frequencies[0], colors[0].r,
- colors[0].g, colors[0].b);
-
- } else {
- fprintf(stdout, "%f|%f|%i|%d:%d:%d\n",
- stats.min, breakpoints[0], frequencies[0], colors[0].r,
- colors[0].g, colors[0].b);
+ nfeatures = Vect_get_num_primitives(&Map, GV_BOUNDARY);
+ if (nfeatures > 0) {
+ write_into_legend_file("stdout", icon_area_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "area");
+ break;
}
+ }
+ }
- for (i = 1; i < nbreaks; i++) {
- fprintf(stdout, "%f|%f|%i|%d:%d:%d\n",
- breakpoints[i - 1], breakpoints[i], frequencies[i],
- colors[i].r, colors[i].g, colors[i].b);
- }
-
- if(stats.max < breakpoints[nbreaks-1]){
- fprintf(stdout, ">%f|%i|%d:%d:%d\n",
- breakpoints[nbreaks - 1], frequencies[nbreaks],
- colors[nbreaks].r, colors[nbreaks].g, colors[nbreaks].b);
- } else {
- fprintf(stdout, "%f|%f|%i|%d:%d:%d\n",
- breakpoints[nbreaks - 1], stats.max, frequencies[nbreaks],
- colors[nbreaks].r, colors[nbreaks].g, colors[nbreaks].b);
+ /* Write into default legfile */
+ leg_file = getenv("GRASS_LEGEND_FILE");
+ if (leg_file && !vlegend_flag->answer) {
+ while (TRUE) {
+ nfeatures = Vect_get_num_primitives(&Map, GV_POINT);
+ if (nfeatures > 0) {
+ write_into_legend_file(leg_file, icon_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "point");
+ break;
}
+ nfeatures = Vect_get_num_primitives(&Map, GV_LINE);
+ if (nfeatures > 0) {
+ write_into_legend_file(leg_file, icon_line_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "line");
+ break;
}
+ nfeatures = Vect_get_num_primitives(&Map, GV_BOUNDARY);
+ if (nfeatures > 0) {
+ write_into_legend_file(leg_file, icon_area_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "area");
+ break;
+ }
+ }
+ }
+ /* Write into user-specified output file */
+
if (legend_file_opt->answer) {
- fd = fopen(legend_file_opt->answer, "w");
- boxsize = 25;
- textsize = 8;
- fprintf(fd, "size %i %i\n", textsize, textsize);
- ypos = 10;
- fprintf(fd, "symbol basic/box %i 5 %i black %d:%d:%d\n", boxsize,
- ypos, colors[0].r, colors[0].g, colors[0].b);
- fprintf(fd, "move 8 %i \n", ypos-1);
- if(stats.min > breakpoints[0]){
- fprintf(fd, "text <%f | %i\n", breakpoints[0],
- frequencies[0]);
- } else {
- fprintf(fd, "text %f - %f | %i\n", stats.min, breakpoints[0],
- frequencies[0]);
+ while (TRUE) {
+ nfeatures = Vect_get_num_primitives(&Map, GV_POINT);
+ if (nfeatures > 0) {
+ write_into_legend_file(legend_file_opt->answer, icon_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "point");
+ break;
}
- for (i = 1; i < nbreaks; i++) {
- ypos = 10 + i * 6;
- fprintf(fd, "symbol basic/box %i 5 %i black %d:%d:%d\n", boxsize,
- ypos, colors[i].r, colors[i].g, colors[i].b);
- fprintf(fd, "move 8 %i\n", ypos-1);
- fprintf(fd, "text %f - %f | %i\n", breakpoints[i - 1],
- breakpoints[i], frequencies[i]);
+ nfeatures = Vect_get_num_primitives(&Map, GV_LINE);
+ if (nfeatures > 0) {
+ write_into_legend_file(legend_file_opt->answer, icon_line_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "line");
+ break;
}
- ypos = 10 + i * 6;
- fprintf(fd, "symbol basic/box %i 5 %i black %d:%d:%d\n", boxsize,
- ypos, colors[nbreaks].r, colors[nbreaks].g,
- colors[nbreaks].b);
- fprintf(fd, "move 8 %i\n", ypos -1);
- if(stats.max < breakpoints[nbreaks-1]){
- fprintf(fd, "text >%f | %i\n", breakpoints[nbreaks - 1],
- frequencies[nbreaks]);
- } else {
- fprintf(fd, "text %f - %f | %i\n", breakpoints[nbreaks - 1],
- stats.max, frequencies[nbreaks]);
+ nfeatures = Vect_get_num_primitives(&Map, GV_BOUNDARY);
+ if (nfeatures > 0) {
+ write_into_legend_file(legend_file_opt->answer, icon_area_opt->answer,
+ title, stats.min, stats.max, breakpoints,
+ nbreaks, size, bcolor, colors, default_width,
+ frequencies, "area");
+ break;
}
- fclose(fd);
}
+ }
if (verbose)
G_done_msg(" ");
@@ -527,3 +636,77 @@
exit(stat);
}
+
+int cmp(const void *a, const void *b)
+{
+ return (strcmp(*(char **)a, *(char **)b));
+}
+
+/* adopted from r.colors */
+char *icon_files(void)
+{
+ char **list, *ret;
+ char buf[GNAME_MAX], path[GPATH_MAX], path_i[GPATH_MAX];
+ int i, count;
+ size_t len;
+ DIR *dir, *dir_i;
+ struct dirent *d, *d_i;
+
+ list = NULL;
+ len = 0;
+ sprintf(path, "%s/etc/symbol", G_gisbase());
+
+ dir = opendir(path);
+ if (!dir)
+ return NULL;
+
+ count = 0;
+
+ /* loop over etc/symbol */
+ while ((d = readdir(dir))) {
+ if (d->d_name[0] == '.')
+ continue;
+
+ sprintf(path_i, "%s/etc/symbol/%s", G_gisbase(), d->d_name);
+ dir_i = opendir(path_i);
+
+ if (!dir_i)
+ continue;
+
+ /* loop over each directory in etc/symbols */
+ while ((d_i = readdir(dir_i))) {
+ if (d_i->d_name[0] == '.')
+ continue;
+
+ list = G_realloc(list, (count + 1) * sizeof(char *));
+
+ sprintf(buf, "%s/%s", d->d_name, d_i->d_name);
+ list[count++] = G_store(buf);
+
+ len += strlen(d->d_name) + strlen(d_i->d_name) + 2; /* '/' + ',' */
+ }
+
+ closedir(dir_i);
+ }
+
+ closedir(dir);
+
+ qsort(list, count, sizeof(char *), cmp);
+
+ if (len > 0) {
+ ret = G_malloc((len + 1) * sizeof(char)); /* \0 */
+ *ret = '\0';
+ for (i = 0; i < count; i++) {
+ if (i > 0)
+ strcat(ret, ",");
+ strcat(ret, list[i]);
+ G_free(list[i]);
+ }
+ G_free(list);
+ }
+ else {
+ ret = G_store("");
+ }
+
+ return ret;
+}
Modified: grass/branches/releasebranch_7_2/gui/wxpython/core/render.py
===================================================================
--- grass/branches/releasebranch_7_2/gui/wxpython/core/render.py 2016-08-31 03:25:43 UTC (rev 69309)
+++ grass/branches/releasebranch_7_2/gui/wxpython/core/render.py 2016-08-31 03:34:50 UTC (rev 69310)
@@ -324,7 +324,7 @@
"""Represents map layer in the map canvas
"""
Layer.__init__(self, *args, **kwargs)
- if self.type in ('vector'): # will add d.vect.thematic
+ if self.type in ('vector', 'thememap'):
self._legrow = grass.tempfile(create=True)
else:
self._legrow = ''
@@ -388,7 +388,7 @@
env_cmd = env.copy()
env_cmd.update(self._render_env)
env_cmd['GRASS_RENDER_FILE'] = self.layer.mapfile
- if self.layer.GetType() in ('vector'):
+ if self.layer.GetType() in ('vector', 'thememap'):
if os.path.isfile(self.layer._legrow):
os.remove(self.layer._legrow)
env_cmd['GRASS_LEGEND_FILE'] = self.layer._legrow
@@ -630,7 +630,7 @@
new_legend = []
with open(self.Map.legfile, "w") as outfile:
for layer in reversed(self.layers):
- if layer.GetType() not in ('vector'):
+ if layer.GetType() not in ('vector', 'thememap'):
continue
if os.path.isfile(layer._legrow) and layer._legrow[-1].isdigit() \
@@ -1279,6 +1279,7 @@
if layer.type == 'wms':
renderMgr.dataFetched.connect(self.renderMgr.ReportProgress)
renderMgr.updateProgress.connect(self.renderMgr.ReportProgress)
+ renderMgr.renderingFailed.connect(self.renderMgr.RenderingFailed)
layer.forceRender = render
self.layerAdded.emit(layer=layer)
@@ -1320,7 +1321,7 @@
for f in glob.glob(basefile):
os.remove(f)
- if layer.GetType() in ('vector'):
+ if layer.GetType() in ('vector', 'thememap'):
os.remove(layer._legrow)
list.remove(layer)
Modified: grass/branches/releasebranch_7_2/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/branches/releasebranch_7_2/gui/wxpython/lmgr/layertree.py 2016-08-31 03:25:43 UTC (rev 69309)
+++ grass/branches/releasebranch_7_2/gui/wxpython/lmgr/layertree.py 2016-08-31 03:34:50 UTC (rev 69310)
@@ -89,7 +89,7 @@
'layerVector': MetaIcon(img='vector',
label=_('Add vector map layer')),
'layerThememap': MetaIcon(img='vector-thematic',
- label=_('Add thematic area (choropleth) map layer')),
+ label=_('Add thematic (choropleth) vector map layer')),
'layerThemechart': MetaIcon(img='vector-chart',
label=_('Add thematic chart layer')),
'layerGrid': MetaIcon(img='layer-grid-add',
More information about the grass-commit
mailing list