|
@@ -11,7 +11,7 @@ int loadSiteCoordinates(struct Map_info *Map, struct Point **points, int region,
|
|
|
struct line_pnts *sites;
|
|
|
struct line_cats *cats;
|
|
|
struct bound_box box;
|
|
|
- int cat, type;
|
|
|
+ int type;
|
|
|
|
|
|
sites = Vect_new_line_struct();
|
|
|
cats = Vect_new_cats_struct();
|
|
@@ -27,26 +27,12 @@ int loadSiteCoordinates(struct Map_info *Map, struct Point **points, int region,
|
|
|
if (type != GV_POINT && !(type & GV_LINES))
|
|
|
continue;
|
|
|
|
|
|
- if (cat_list) {
|
|
|
- int found = 0;
|
|
|
-
|
|
|
- for (i = 0; i < cats->n_cats; i++) {
|
|
|
- if (cats->field[i] == field &&
|
|
|
- Vect_cat_in_cat_list(cats->cat[i], cat_list)) {
|
|
|
-
|
|
|
- found = 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!found)
|
|
|
- continue;
|
|
|
- }
|
|
|
- else if (field > 0 && Vect_cat_get(cats, field, &cat) == 0)
|
|
|
+ if (field > 0 && !Vect_cats_in_constraint(cats, field, cat_list))
|
|
|
continue;
|
|
|
|
|
|
for (i = 0; i < sites->n_points; i++) {
|
|
|
- G_debug(4, "Point: %f|%f|%f|#%d", sites->x[i], sites->y[i],
|
|
|
- sites->z[i], cat);
|
|
|
+ G_debug(4, "Point: %f|%f|%f", sites->x[i], sites->y[i],
|
|
|
+ sites->z[i]);
|
|
|
|
|
|
if (region && !Vect_point_in_box(sites->x[i], sites->y[i], sites->z[i], &box))
|
|
|
continue;
|
|
@@ -70,92 +56,3 @@ int loadSiteCoordinates(struct Map_info *Map, struct Point **points, int region,
|
|
|
|
|
|
return pointIdx;
|
|
|
}
|
|
|
-
|
|
|
-static int cmp_int(const void *a, const void *b)
|
|
|
-{
|
|
|
- int ai = *(int *)a;
|
|
|
- int bi = *(int *)b;
|
|
|
-
|
|
|
- return (ai < bi ? -1 : (ai > bi));
|
|
|
-}
|
|
|
-
|
|
|
-/* parse filter options */
|
|
|
-/* return cat list or NULL */
|
|
|
-struct cat_list *parse_filter_options(struct Map_info *Map, int layer,
|
|
|
- char *where, char *catstr)
|
|
|
-{
|
|
|
- struct cat_list *list = NULL;
|
|
|
-
|
|
|
- if (where) {
|
|
|
- struct field_info *Fi = NULL;
|
|
|
- dbDriver *driver = NULL;
|
|
|
- int ncats, *cats = NULL;
|
|
|
- int i, j;
|
|
|
-
|
|
|
- if (layer < 1)
|
|
|
- G_fatal_error(_("'%s' must be > 0 for '%s'"), "layer", "where");
|
|
|
- if (catstr)
|
|
|
- G_warning(_("'where' and 'cats' parameters were supplied, cat will be ignored"));
|
|
|
-
|
|
|
- Fi = Vect_get_field(Map, layer);
|
|
|
- if (!Fi) {
|
|
|
- G_fatal_error(_("Database connection not defined for layer %d"),
|
|
|
- layer);
|
|
|
- }
|
|
|
-
|
|
|
- G_verbose_message(_("Loading categories from table <%s>..."), Fi->table);
|
|
|
-
|
|
|
- driver = db_start_driver_open_database(Fi->driver, Fi->database);
|
|
|
- if (driver == NULL)
|
|
|
- G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
|
|
|
- Fi->database, Fi->driver);
|
|
|
-
|
|
|
- ncats = db_select_int(driver, Fi->table, Fi->key, where,
|
|
|
- &cats);
|
|
|
- if (ncats == -1)
|
|
|
- G_fatal_error(_("Unable select records from table <%s>"),
|
|
|
- Fi->table);
|
|
|
- G_verbose_message(_("%d categories loaded"), ncats);
|
|
|
-
|
|
|
- db_close_database_shutdown_driver(driver);
|
|
|
-
|
|
|
- /* sort */
|
|
|
- qsort(cats, ncats, sizeof(int), cmp_int);
|
|
|
-
|
|
|
- /* remove duplicates */
|
|
|
- j = 1;
|
|
|
- for (i = 1; i < ncats; i++) {
|
|
|
- if (cats[i] != cats[j - 1]) {
|
|
|
- cats[j] = cats[i];
|
|
|
- j++;
|
|
|
- }
|
|
|
- }
|
|
|
- ncats = j;
|
|
|
-
|
|
|
- /* convert to cat list */
|
|
|
- list = Vect_new_cat_list();
|
|
|
-
|
|
|
- Vect_array_to_cat_list(cats, ncats, list);
|
|
|
-
|
|
|
- if (cats)
|
|
|
- G_free(cats);
|
|
|
- }
|
|
|
- else if (catstr) {
|
|
|
- if (layer < 1)
|
|
|
- G_fatal_error(_("'%s' must be > 0 for '%s'"), "layer", GV_KEY_COLUMN);
|
|
|
- list = Vect_new_cat_list();
|
|
|
-
|
|
|
- if (Vect_str_to_cat_list(catstr, list) > 0) {
|
|
|
- G_warning(_("Problem loading category values"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (list) {
|
|
|
- if (list->n_ranges < 1) {
|
|
|
- Vect_destroy_cat_list(list);
|
|
|
- list = NULL;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return list;
|
|
|
-}
|