[GRASS-SVN] r32264 - grass/trunk/display/d.thematic.area

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 24 12:41:09 EDT 2008


Author: mlennert
Date: 2008-07-24 12:41:04 -0400 (Thu, 24 Jul 2008)
New Revision: 32264

Modified:
   grass/trunk/display/d.thematic.area/area.c
   grass/trunk/display/d.thematic.area/local_proto.h
   grass/trunk/display/d.thematic.area/main.c
Log:
rearranged some of the code, to allow running without x-mon for only legend output
improved the d.graph output


Modified: grass/trunk/display/d.thematic.area/area.c
===================================================================
--- grass/trunk/display/d.thematic.area/area.c	2008-07-24 15:16:43 UTC (rev 32263)
+++ grass/trunk/display/d.thematic.area/area.c	2008-07-24 16:41:04 UTC (rev 32264)
@@ -14,9 +14,9 @@
 #include "local_proto.h"
 
 int dareatheme(struct Map_info *Map, struct cat_list *Clist,
-	       dbCatValArray * cvarr, double *breaks, int nbreaks,
+	       dbCatValArray *cvarr, double *breaks, int nbreaks,
 	       const struct color_rgb *colors, const struct color_rgb *bcolor,
-	       int chcat, struct Cell_head *window, int default_width, int *frequencies, int nodraw)
+	       int chcat, struct Cell_head *window, int default_width)
 {
 
     int num, area, isle, n_isles, n_points;
@@ -33,11 +33,15 @@
     IPoints = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
 
+    /* We need to sort the CatValArray by cat for the bsearch in 
+     * db_CatValArray_get_value 
+     */
+    db_CatValArray_sort(cvarr);
 
     num = Vect_get_num_areas(Map);
     G_debug(2, "n_areas = %d", num);
-   
 
+
     for (area = 1; area <= num; area++) {
 	int i;
 	BOUND_BOX box;
@@ -146,13 +150,6 @@
 	    }
 	}
 
-	/* find out into which class breakval falls */
-	i = 0;
-	while (breakval > breaks[i] && i < nbreaks)
-	    i++;
-	frequencies[i]++;
-
-        if(!nodraw) {
 	/* plot polygon in class color */
 	R_RGB_color(colors[i].r, colors[i].g, colors[i].b);
 	plot_polygon(Points->x, Points->y, Points->n_points);
@@ -171,7 +168,6 @@
 		plot_polyline(Points->x, Points->y, Points->n_points);
 	    }
 	}
-      } /* end if !nodraw */
     }				/* end for loop over areas */
 
     Vect_destroy_line_struct(Points);

Modified: grass/trunk/display/d.thematic.area/local_proto.h
===================================================================
--- grass/trunk/display/d.thematic.area/local_proto.h	2008-07-24 15:16:43 UTC (rev 32263)
+++ grass/trunk/display/d.thematic.area/local_proto.h	2008-07-24 16:41:04 UTC (rev 32264)
@@ -9,7 +9,7 @@
 	  int, int, int, int, char *, int, char *, double);
 int dareatheme(struct Map_info *, struct cat_list *, dbCatValArray *, double *, int,
 	  const struct color_rgb *, const struct color_rgb *, int,
-	  struct Cell_head *, int, int *, int);
+	  struct Cell_head *, int);
 void plot_polygon(double *, double *, int);
 void plot_polyline(double *, double *, int);
 

Modified: grass/trunk/display/d.thematic.area/main.c
===================================================================
--- grass/trunk/display/d.thematic.area/main.c	2008-07-24 15:16:43 UTC (rev 32263)
+++ grass/trunk/display/d.thematic.area/main.c	2008-07-24 16:41:04 UTC (rev 32264)
@@ -35,7 +35,7 @@
     char *mapset;
     int ret, level;
     int i, stat = 0;
-    int nclass = 0, nbreaks, *frequencies, boxsize = 0;
+    int nclass = 0, nbreaks, *frequencies, boxsize, textsize, ypos;
     int chcat = 0;
     int r, g, b;
     int has_color = 0;
@@ -67,7 +67,8 @@
     dbCatValArray cvarr;
     struct Cell_head window;
     BOUND_BOX box;
-    double overlap, *breakpoints, min = 0, max = 0, *data = NULL, class_info = 0.0;
+    double overlap, *breakpoints, min = 0, max = 0, *data = NULL, class_info =
+	0.0;
     struct GASTATS stats;
     FILE *fd;
 
@@ -383,18 +384,16 @@
 	else {
 
 	    G_fatal_error(_
-			  ("You must either give classbreaks or a classification algrorithm"));
+			  ("You must either give classbreaks or a classification algorithm"));
 
 	}
     };
 
-    frequencies = (int *)G_malloc((nbreaks + 1) * sizeof(int));
-    for (i = 0; i < nbreaks + 1; i++)
-	frequencies[i] = 0;
 
     /* Fill colors */
     colors = (struct color_rgb *)G_malloc(nclass * sizeof(struct color_rgb));
 
+
     if (colors_opt->answers != NULL) {
 	for (i = 0; i < nclass; i++) {
 	    if (colors_opt->answers[i] == NULL)
@@ -414,75 +413,81 @@
     }
 
 
-    /* Not sure if this is needed, but probably won't hurt */
-    db_CatValArray_sort(&cvarr);
+    if (!nodraw_flag->answer) {
+	/* Now's let's prepare the actual plotting */
+	if (R_open_driver() != 0)
+	    G_fatal_error(_("No graphics device selected"));
 
-    /* Now's let's prepare the actual plotting */
-    if (R_open_driver() != 0)
-	G_fatal_error(_("No graphics device selected"));
+	D_setup(0);
 
-    D_setup(0);
+	G_setup_plot(D_get_d_north(), D_get_d_south(),
+		     D_get_d_west(), D_get_d_east(), D_move_abs, D_cont_abs);
 
-    G_setup_plot(D_get_d_north(), D_get_d_south(),
-		 D_get_d_west(), D_get_d_east(), D_move_abs, D_cont_abs);
+	if (verbose)
+	    G_message(_("Plotting ..."));
 
-    if (verbose)
-	G_message(_("Plotting ..."));
+	Vect_get_map_box(&Map, &box);
 
-    Vect_get_map_box(&Map, &box);
+	if (window.north < box.S || window.south > box.N ||
+	    window.east < box.W ||
+	    window.west > G_adjust_easting(box.E, &window)) {
+	    G_message(_
+		      ("The bounding box of the map is outside the current region, "
+		       "nothing drawn."));
+	    stat = 0;
+	}
+	else {
+	    overlap =
+		G_window_percentage_overlap(&window, box.N, box.S, box.E,
+					    box.W);
+	    G_debug(1, "overlap = %f \n", overlap);
+	    if (overlap < 1)
+		Vect_set_constraint_region(&Map, window.north, window.south,
+					   window.east, window.west,
+					   PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX);
 
-    if (window.north < box.S || window.south > box.N ||
-	window.east < box.W || window.west > G_adjust_easting(box.E, &window)) {
-	G_message(_
-		  ("The bounding box of the map is outside the current region, "
-		   "nothing drawn."));
-	stat = 0;
-    }
-    else {
-	overlap =
-	    G_window_percentage_overlap(&window, box.N, box.S, box.E, box.W);
-	G_debug(1, "overlap = %f \n", overlap);
-	if (overlap < 1)
-	    Vect_set_constraint_region(&Map, window.north, window.south,
-				       window.east, window.west,
-				       PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX);
+	    /* default line width */
+	    D_line_width(default_width);
 
-	/* default line width */
-	D_line_width(default_width);
 
+	    stat = dareatheme(&Map, Clist, &cvarr, breakpoints, nbreaks, colors,
+			      has_color ? &bcolor : NULL, chcat, &window,
+			      default_width);
 
-	stat = dareatheme(&Map, Clist, &cvarr, breakpoints, nbreaks, colors,
-			  has_color ? &bcolor : NULL, chcat, &window,
-			  default_width, frequencies, nodraw_flag->answer);
 
+	    /* 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.,
+	     * d.linewidth). */
+	    R_line_width(0);
 
-	/* 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.,
-	 * d.linewidth). */
-	R_line_width(0);
+	}			/* end window check if */
 
-    }				/* end window check if */
+	if (!x_flag->answer) {
+	    D_add_to_list(G_recreate_command());
 
-    if (!x_flag->answer) {
-	D_add_to_list(G_recreate_command());
+	    D_set_dig_name(G_fully_qualified_name(map_name, mapset));
+	    D_add_to_dig_list(G_fully_qualified_name(map_name, mapset));
+	}
 
-	D_set_dig_name(G_fully_qualified_name(map_name, mapset));
-	D_add_to_dig_list(G_fully_qualified_name(map_name, mapset));
-    }
+	R_close_driver();
 
-    R_close_driver();
+    }				/* end of nodraw_flag condition */
 
+    frequencies = (int *)G_malloc((nbreaks + 1) * sizeof(int));
+    for (i = 0; i < nbreaks + 1; i++)
+	frequencies[i] = 0.0;
+    class_frequencies(data, nrec, nbreaks, breakpoints, frequencies);
 
+    if (legend_flag->answer) {
 
-
-
-    if (legend_flag->answer) {
 	if (algoinfo_flag->answer) {
 
 	    basic_stats(data, nrec, &stats);
 
-	    fprintf(stdout, _("\nClassification of %s into %i classes\n"),
+	    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);
@@ -515,21 +520,27 @@
     if (legend_file_opt->answer) {
 	fd = fopen(legend_file_opt->answer, "w");
 	boxsize = 100 / nclass;
-	fprintf(fd, "symbol basic/box %i 5 10 black %d:%d:%d\n", boxsize,
+	textsize = boxsize / 10;
+	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 15 7 \n");
-	fprintf(fd, "text %f - %f\n", min, breakpoints[0]);
+	fprintf(fd, "move 15 %i \n", ypos - textsize / 2);
+	fprintf(fd, "text %f - %f | %i\n", min, breakpoints[0], frequencies[0]);
 	for (i = 1; i < nbreaks; i++) {
+	    ypos = 10 + i * 10;
 	    fprintf(fd, "symbol basic/box %i 5 %i black %d:%d:%d\n", boxsize,
-		    10 + i * 10, colors[i].r, colors[i].g, colors[i].b);
-	    fprintf(fd, "move 15 %i\n", 7 + i * 10);
-	    fprintf(fd, "text %f - %f\n", breakpoints[i - 1], breakpoints[i]);
+		    ypos, colors[i].r, colors[i].g, colors[i].b);
+	    fprintf(fd, "move 15 %i\n", ypos - textsize / 2);
+	    fprintf(fd, "text %f - %f | %i\n", breakpoints[i - 1],
+		    breakpoints[i], frequencies[i]);
 	}
+	ypos = 10 + i * 10;
 	fprintf(fd, "symbol basic/box %i 5 %i black %d:%d:%d\n", boxsize,
-		10 + i * 10, colors[nbreaks].r, colors[nbreaks].g,
-		colors[nbreaks].b);
-	fprintf(fd, "move 15 %i\n", 7 + i * 10);
-	fprintf(fd, "text %f - %f\n", breakpoints[nbreaks - 1], max);
+		ypos, colors[nbreaks].r, colors[nbreaks].g, colors[nbreaks].b);
+	fprintf(fd, "move 15 %i\n", ypos - textsize / 2);
+	fprintf(fd, "text %f - %f | %i\n", breakpoints[nbreaks - 1], max,
+		frequencies[nbreaks]);
 	fclose(fd);
     }
 



More information about the grass-commit mailing list