21 #include <grass/gis.h>
22 #include <grass/dbmi.h>
23 #include <grass/Vect.h>
24 #include <grass/glocale.h>
28 static int cmp(
const void *pa,
const void *pb);
29 static int in_array(
int *cats,
size_t ncats,
int cat);
48 p = (VARRAY *) G_malloc(
sizeof(VARRAY));
54 p->c = (
int *)G_calloc(
sizeof(
char) * size + 1,
sizeof(int));
90 struct cat_list *Clist;
92 G_debug(4,
"Vect_set_varray_from_cat_string(): cstring = '%s'", cstring);
99 G_warning(_(
"%d errors in category string."), ret);
101 G_debug(4,
" %d ranges in clist", Clist->n_ranges);
133 struct cat_list *clist,
int type,
int value,
136 int i, n, centr, cat;
139 struct line_cats *Cats;
141 G_debug(4,
"Vect_set_varray_from_cat_list(): field = %d", field);
144 if ((type & GV_AREA) && (type & (GV_POINTS |
GV_LINES))) {
145 G_warning(_(
"Mixed area and other type requested for vector array"));
151 if (type & GV_AREA) {
154 if (n > varray->size) {
155 G_warning(_(
"Not enough space in vector array"));
159 for (i = 1; i <= n; i++) {
169 varray->c[i] =
value;
177 if (n > varray->size) {
178 G_warning(_(
"Not enough space in vector array"));
182 for (i = 1; i <= n; i++) {
192 varray->c[i] =
value;
205 static int cmp(
const void *pa,
const void *pb)
218 static int in_array(
int *cats,
size_t ncats,
int cat)
222 p = (
int *)bsearch((
void *)&cat, cats, ncats,
sizeof(int), cmp);
254 int i, n, c, centr, cat, *cats;
258 struct line_cats *Cats;
259 struct field_info *Fi;
262 G_debug(4,
"Vect_set_varray_from_db(): field = %d where = '%s'", field,
268 if ((type & GV_AREA) && (type & (GV_POINTS |
GV_LINES))) {
269 G_warning(_(
"Mixed area and other type requested for vector array"));
278 G_warning(_(
"Database connection not defined for layer %d"), field);
283 if (driver ==
NULL) {
284 G_warning(_(
"Unable to open database <%s> by driver <%s>"),
285 Fi->database, Fi->driver);
289 ncats =
db_select_int(driver, Fi->table, Fi->key, where, &cats);
294 G_warning(_(
"Unable to select record from table <%s> (key %s, where %s)"),
295 Fi->table, Fi->key, where);
299 if (type & GV_AREA) {
305 if (n > varray->size) {
306 G_warning(_(
"Not enough space in vector array"));
310 for (i = 1; i <= n; i++) {
317 for (c = 0; c < Cats->n_cats; c++) {
318 if (Cats->field[c] == field &&
319 in_array(cats, ncats, Cats->cat[c])) {
321 varray->c[i] =
value;
338 if (n > varray->size) {
339 G_warning(_(
"Not enough space in vector array"));
343 for (i = 1; i <= n; i++) {
350 for (c = 0; c < Cats->n_cats; c++) {
351 if (Cats->field[c] == field &&
352 in_array(cats, ncats, Cats->cat[c])) {
354 varray->c[i] =
value;