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;
dbDriver * db_start_driver_open_database(const char *drvname, const char *dbname)
Open driver/database connection.
void G_free(void *buf)
Free allocated memory.
int Vect_get_area_centroid(struct Map_info *Map, int area)
Returns centroid number of area.
struct field_info * Vect_get_field(struct Map_info *Map, int field)
Get information about link to database.
int Vect_set_varray_from_db(struct Map_info *Map, int field, const char *where, int type, int value, VARRAY *varray)
Set values in 'varray' to 'value'.
int Vect_destroy_cat_list(struct cat_list *p)
Frees allocated cat_list memory.
int db_close_database_shutdown_driver(dbDriver *driver)
Close driver/database connection.
int Vect_set_varray_from_cat_list(struct Map_info *Map, int field, struct cat_list *clist, int type, int value, VARRAY *varray)
Set values in 'varray' to 'value'.
int Vect_get_num_areas(struct Map_info *map)
Get number of areas in vector map.
int db_select_int(dbDriver *driver, const char *tab, const char *col, const char *where, int **pval)
Select array of ordered integers from table/column.
int Vect_cat_in_cat_list(int cat, struct cat_list *list)
Check if category number is in list.
int Vect_set_varray_from_cat_string(struct Map_info *Map, int field, const char *cstring, int type, int value, VARRAY *varray)
Set values in 'varray' to 'value'.
struct cat_list * Vect_new_cat_list()
Allocate memory for cat_list structure.
VARRAY * Vect_new_varray(int size)
Create new VARRAY and allocate space for given number of items.
int Vect_destroy_cats_struct(struct line_cats *p)
Frees all memory associated with line_cats structure, including the struct itself.
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int Vect_get_num_lines(struct Map_info *map)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
int G_debug(int level, const char *msg,...)
Print debugging message.
int Vect_str_to_cat_list(const char *str, struct cat_list *list)
Convert string of categories and cat ranges separated by commas to cat_list.
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.
int Vect_cat_get(struct line_cats *Cats, int field, int *cat)
Get first found category of given field.