|
@@ -25,7 +25,7 @@ struct vstat vstat;
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
- int n;
|
|
|
+ int n, i, j, cat, lastcat, type, id, findex;
|
|
|
struct Map_info Map;
|
|
|
struct GModule *module;
|
|
|
struct field_info *Fi;
|
|
@@ -69,17 +69,62 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
/* allocate array for values */
|
|
|
/* (+ 1 is for cat -1 (no category) reported at the end ) */
|
|
|
+ findex = Vect_cidx_get_field_index(&Map, options.field);
|
|
|
if (Vect_cidx_get_field_index(&Map, options.field) > -1) {
|
|
|
- n = Vect_cidx_get_num_unique_cats_by_index(&Map,
|
|
|
- Vect_cidx_get_field_index
|
|
|
- (&Map, options.field));
|
|
|
+ n = Vect_cidx_get_num_unique_cats_by_index(&Map, findex);
|
|
|
}
|
|
|
else {
|
|
|
n = 0;
|
|
|
}
|
|
|
G_debug(2, "%d unique cats", n);
|
|
|
Values = (struct value *) G_calloc(n + 1, sizeof(struct value));
|
|
|
- vstat.rcat = 0;
|
|
|
+
|
|
|
+ /* prepopulate Values */
|
|
|
+ n = Vect_cidx_get_num_cats_by_index(&Map, findex);
|
|
|
+ i = 0;
|
|
|
+ Values[i].cat = -1; /* features without category */
|
|
|
+ Values[i].used = 0;
|
|
|
+ Values[i].count1 = 0;
|
|
|
+ Values[i].count1 = 0;
|
|
|
+ Values[i].i1 = -1;
|
|
|
+ Values[i].i2 = -1;
|
|
|
+ Values[i].d1 = 0.0;
|
|
|
+ Values[i].d2 = 0.0;
|
|
|
+ Values[i].qcat = NULL;
|
|
|
+ Values[i].nqcats = 0;
|
|
|
+ Values[i].aqcats = 0;
|
|
|
+
|
|
|
+ i = 1;
|
|
|
+ lastcat = -1;
|
|
|
+ /* category index must be sorted,
|
|
|
+ * i.e. topology must have been built with GV_BUILD_ALL */
|
|
|
+ for (j = 0; j < n; j++) {
|
|
|
+ Vect_cidx_get_cat_by_index(&Map, findex, j, &cat, &type, &id);
|
|
|
+ if (lastcat > cat) {
|
|
|
+ Vect_close(&Map);
|
|
|
+ G_fatal_error(_("Category index for vector map <%s> is not sorted"),
|
|
|
+ options.name);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lastcat != cat) {
|
|
|
+ Values[i].cat = cat;
|
|
|
+ Values[i].used = 0;
|
|
|
+ Values[i].count1 = 0;
|
|
|
+ Values[i].count1 = 0;
|
|
|
+ Values[i].i1 = -1;
|
|
|
+ Values[i].i2 = -1;
|
|
|
+ Values[i].d1 = 0.0;
|
|
|
+ Values[i].d2 = 0.0;
|
|
|
+ Values[i].qcat = NULL;
|
|
|
+ Values[i].nqcats = 0;
|
|
|
+ Values[i].aqcats = 0;
|
|
|
+
|
|
|
+ lastcat = cat;
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ vstat.rcat = i;
|
|
|
|
|
|
/* Read values from map */
|
|
|
if (options.option == O_QUERY) {
|
|
@@ -93,6 +138,17 @@ int main(int argc, char *argv[])
|
|
|
read_lines(&Map);
|
|
|
}
|
|
|
|
|
|
+ /* prune unused values */
|
|
|
+ n = vstat.rcat;
|
|
|
+ j = 0;
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
+ if (Values[i].used) {
|
|
|
+ Values[j] = Values[i];
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vstat.rcat = j;
|
|
|
+
|
|
|
conv_units();
|
|
|
|
|
|
if (options.print || options.total) {
|