[GRASS-SVN] r63911 - in grass/trunk: display/d.thematic.area include include/defs lib/arraystats vector/v.class
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jan 1 11:45:15 PST 2015
Author: martinl
Date: 2015-01-01 11:45:14 -0800 (Thu, 01 Jan 2015)
New Revision: 63911
Modified:
grass/trunk/display/d.thematic.area/main.c
grass/trunk/include/arraystats.h
grass/trunk/include/defs/arraystats.h
grass/trunk/lib/arraystats/class.c
grass/trunk/vector/v.class/main.c
Log:
arraystatslib: add AS_option_to_algorithm()
Modified: grass/trunk/display/d.thematic.area/main.c
===================================================================
--- grass/trunk/display/d.thematic.area/main.c 2015-01-01 19:26:41 UTC (rev 63910)
+++ grass/trunk/display/d.thematic.area/main.c 2015-01-01 19:45:14 UTC (rev 63911)
@@ -325,9 +325,9 @@
/* Get classbreaks for given algorithm and number of classbreaks.
* class_info takes any info coming from the classification algorithms */
- class_info =
- AS_class_apply_algorithm(algo_opt->answer, data, nrec, &nbreaks,
- breakpoints);
+ class_info = AS_class_apply_algorithm(AS_option_to_algorithm(algo_opt),
+ data, nrec, &nbreaks,
+ breakpoints);
}
else {
Modified: grass/trunk/include/arraystats.h
===================================================================
--- grass/trunk/include/arraystats.h 2015-01-01 19:26:41 UTC (rev 63910)
+++ grass/trunk/include/arraystats.h 2015-01-01 19:45:14 UTC (rev 63911)
@@ -22,6 +22,12 @@
double stdev;
};
+#define CLASS_INTERVAL 1
+#define CLASS_STDEV 2
+#define CLASS_QUANT 3
+#define CLASS_EQUIPROB 4
+#define CLASS_DISCONT 5
+
#include <grass/defs/arraystats.h>
#endif
Modified: grass/trunk/include/defs/arraystats.h
===================================================================
--- grass/trunk/include/defs/arraystats.h 2015-01-01 19:26:41 UTC (rev 63910)
+++ grass/trunk/include/defs/arraystats.h 2015-01-01 19:45:14 UTC (rev 63911)
@@ -6,7 +6,8 @@
void AS_basic_stats(double *, int, struct GASTATS *);
/* class.c */
-double AS_class_apply_algorithm(char *, double *, int, int *, double *);
+int AS_option_to_algorithm(const struct Option *);
+double AS_class_apply_algorithm(int, double *, int, int *, double *);
int AS_class_interval(double *, int, int, double *);
int AS_class_quant(double *, int, int, double *);
double AS_class_discont(double *, int, int, double *);
Modified: grass/trunk/lib/arraystats/class.c
===================================================================
--- grass/trunk/lib/arraystats/class.c 2015-01-01 19:26:41 UTC (rev 63910)
+++ grass/trunk/lib/arraystats/class.c 2015-01-01 19:45:14 UTC (rev 63911)
@@ -3,27 +3,50 @@
#include <grass/glocale.h>
#include <grass/arraystats.h>
-double AS_class_apply_algorithm(char *algo, double *data, int nrec, int *nbreaks,
+int AS_option_to_algorithm(const struct Option * option)
+{
+ if (G_strcasecmp(option->answer, "int") == 0)
+ return CLASS_INTERVAL;
+ if (G_strcasecmp(option->answer, "std") == 0)
+ return CLASS_STDEV;
+ if (G_strcasecmp(option->answer, "qua") == 0)
+ return CLASS_QUANT;
+ if (G_strcasecmp(option->answer, "equ") == 0)
+ return CLASS_EQUIPROB;
+ if (G_strcasecmp(option->answer, "dis") == 0)
+ return CLASS_DISCONT;
+
+ G_fatal_error(_("Unknown algorithm '%s'"), option->answer);
+}
+
+double AS_class_apply_algorithm(int algo, double *data, int nrec, int *nbreaks,
double *classbreaks)
{
double finfo = 0.0;
- if (G_strcasecmp(algo, "int") == 0)
- finfo = AS_class_interval(data, nrec, *nbreaks, classbreaks);
- else if (G_strcasecmp(algo, "std") == 0)
- finfo = AS_class_stdev(data, nrec, *nbreaks, classbreaks);
- else if (G_strcasecmp(algo, "qua") == 0)
+ switch (algo) {
+ case CLASS_INTERVAL:
+ finfo = AS_class_interval(data, nrec, *nbreaks, classbreaks);
+ break;
+ case CLASS_STDEV:
+ finfo = AS_class_stdev(data, nrec, *nbreaks, classbreaks);
+ break;
+ case CLASS_QUANT:
finfo = AS_class_quant(data, nrec, *nbreaks, classbreaks);
- else if (G_strcasecmp(algo, "equ") == 0)
- finfo = AS_class_equiprob(data, nrec, nbreaks, classbreaks);
- else if (G_strcasecmp(algo, "dis") == 0)
- /* finfo = class_discont(data, nrec, *nbreaks, classbreaks); disabled because of bugs */
+ break;
+ case CLASS_EQUIPROB:
+ finfo = AS_class_equiprob(data, nrec, nbreaks, classbreaks);
+ break;
+ case CLASS_DISCONT:
+ /* 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);
+ break;
+ default:
+ break;
+ }
if (finfo == 0)
- G_fatal_error(_("%s: Error in classification algorithm"), algo);
+ G_fatal_error(_("Classification algorithm failed"));
return finfo;
}
Modified: grass/trunk/vector/v.class/main.c
===================================================================
--- grass/trunk/vector/v.class/main.c 2015-01-01 19:26:41 UTC (rev 63910)
+++ grass/trunk/vector/v.class/main.c 2015-01-01 19:45:14 UTC (rev 63911)
@@ -164,10 +164,11 @@
* finfo takes any info coming from the classification algorithms
* equ algorithm can alter number of class breaks */
finfo =
- AS_class_apply_algorithm(algo_opt->answer, data, nrec, &nbreaks,
+ AS_class_apply_algorithm(AS_option_to_algorithm(algo_opt),
+ data, nrec, &nbreaks,
classbreaks);
+
-
if (G_strcasecmp(algo_opt->answer, "dis") == 0 && finfo < 3.84148)
G_warning(_("The discontinuities algorithm indicates that some "
"class breaks are not statistically significant at "
More information about the grass-commit
mailing list