Browse Source

fix small bugs in d.thematic.area and disable discont algorithm until we fix it

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@32688 15284696-431f-4ddb-bdfa-cd5b030d7da7
Moritz Lennert 16 years ago
parent
commit
ac3098c250
4 changed files with 21 additions and 14 deletions
  1. 7 5
      display/d.thematic.area/area.c
  2. 9 5
      display/d.thematic.area/main.c
  3. 3 2
      lib/arraystats/class.c
  4. 2 2
      vector/v.class/main.c

+ 7 - 5
display/d.thematic.area/area.c

@@ -33,11 +33,6 @@ int dareatheme(struct Map_info *Map, struct cat_list *Clist,
     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);
 
@@ -151,6 +146,13 @@ int dareatheme(struct Map_info *Map, struct cat_list *Clist,
 	    }
 	}
 
+        /* find out into which class breakval falls */
+        i = 0;
+        while (breakval > breaks[i] && i < nbreaks)
+        i++;
+
+
+
 	/* 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);

+ 9 - 5
display/d.thematic.area/main.c

@@ -107,8 +107,8 @@ int main(int argc, char **argv)
     algo_opt->descriptions = _("int;simple intervals;"
 			       "std;standard deviations;"
 			       "qua;quantiles;"
-			       "equ;equiprobable (normal distribution);"
-			       "dis;discontinuities");
+			       "equ;equiprobable (normal distribution);");
+/*currently disabled because of bugs       "dis;discontinuities");*/
 
     nbclass_opt = G_define_option();
     nbclass_opt->key = "nbclasses";
@@ -354,6 +354,8 @@ int main(int argc, char **argv)
 		max = cvarr.value[cvarr.n_values - 1].val.d;
 	    }
 
+	    db_CatValArray_sort(&cvarr);
+
 	    nclass = atoi(nbclass_opt->answer);
 	    nbreaks = nclass - 1;	/* we need one less classbreaks (min and 
 					 * max exluded) than classes */
@@ -455,11 +457,13 @@ int main(int argc, char **argv)
 	frequencies[i] = 0.0;
     class_frequencies(data, nrec, nbreaks, breakpoints, frequencies);
 
+    /*Get basic statistics about the data*/
+    basic_stats(data, nrec, &stats);
+
     if (legend_flag->answer) {
 
 	if (algoinfo_flag->answer) {
 
-	    basic_stats(data, nrec, &stats);
 
 	    fprintf(stdout, _("\nTotal number of records: %.0f\n"),
 		    stats.count);
@@ -481,7 +485,7 @@ int main(int argc, char **argv)
 	}
 
 	fprintf(stdout, "%f|%f|%i|%d:%d:%d\n",
-		min, breakpoints[0], frequencies[0], colors[0].r, colors[0].g,
+		stats.min, breakpoints[0], frequencies[0], colors[0].r, colors[0].g,
 		colors[0].b);
 
 	for (i = 1; i < nbreaks; i++) {
@@ -490,7 +494,7 @@ int main(int argc, char **argv)
 		    colors[i].r, colors[i].g, colors[i].b);
 	}
 	fprintf(stdout, "%f|%f|%i|%d:%d:%d\n",
-		breakpoints[nbreaks - 1], max, frequencies[nbreaks],
+		breakpoints[nbreaks - 1], stats.max, frequencies[nbreaks],
 		colors[nbreaks].r, colors[nbreaks].g, colors[nbreaks].b);
     }
 

+ 3 - 2
lib/arraystats/class.c

@@ -17,7 +17,8 @@ double class_apply_algorithm(char *algo, double *data, int nrec, int *nbreaks,
     else if (G_strcasecmp(algo, "equ") == 0)
 	finfo = class_equiprob(data, nrec, nbreaks, classbreaks);
     else if (G_strcasecmp(algo, "dis") == 0)
-	finfo = class_discont(data, nrec, *nbreaks, classbreaks);
+	    /*	finfo = class_discont(data, nrec, *nbreaks, classbreaks); disabled because of bugs */
+        G_fatal_error(_("Discont algorithm currently not available because of bugs"));
     else
 	G_fatal_error(_("%s: Unknown algorithm"), algo);
 
@@ -239,7 +240,7 @@ int class_equiprob(double *data, int count, int *nbreaks, double *classbreaks)
     return (1);
 }
 
-
+/* FixMe: there seems to a problem with array overflow, probably due to the fact that the code was ported from fortran which has 1-based arrays*/
 double class_discont(double *data, int count, int nbreaks,
 		     double *classbreaks)
 {

+ 2 - 2
vector/v.class/main.c

@@ -69,8 +69,8 @@ int main(int argc, char *argv[])
     algo_opt->descriptions = _("int;simple intervals;"
 			       "std;standard deviations;"
 			       "qua;quantiles;"
-			       "equ;equiprobable (normal distribution);"
-			       "dis;discontinuities");
+			       "equ;equiprobable (normal distribution);");
+/*			       "dis;discontinuities"); currently disabled because of bugs*/
 
     nbclass_opt = G_define_option();
     nbclass_opt->key = "nbclasses";