19 #include <sys/types.h> 25 #include "local_proto.h" 27 #define SEP "------------------------------------------------------------------------------------------\n" 29 static void check_status(
const struct Map_info *Map)
35 static void check_index(
const struct Map_info *Map,
int index)
42 static int ci_search_cat(
struct Cat_index *ci,
int first,
int cat)
49 if (ci->
cat[lo][0] > cat)
51 if (ci->
cat[lo][0] == cat)
61 if (ci->
cat[mid][0] < cat)
66 if (ci->
cat[lo][0] == cat)
99 check_index(Map, index);
118 G_debug(2,
"Vect_cidx_get_field_index() field = %d", field);
123 for (i = 0; i < Plus->
n_cidx; i++) {
124 if (Plus->
cidx[i].field == field)
145 check_index(Map, index);
147 return Map->
plus.
cidx[index].n_ucats;
162 check_index(Map, index);
164 return Map->
plus.
cidx[index].n_cats;
181 check_index(Map, field_index);
183 return Map->
plus.
cidx[field_index].n_types;
199 int type_index,
int *type,
int *
count)
202 check_index(Map, field_index);
204 *type = Map->
plus.
cidx[field_index].type[type_index][0];
206 *count = Map->
plus.
cidx[field_index].type[type_index][1];
223 int i, fi,
count = 0;
225 G_debug(3,
"Vect_cidx_get_type_count() field = %d, type = %d", field,
232 G_debug(3,
"field_index = %d", fi);
235 for (i = 0; i < Map->
plus.
cidx[fi].n_types; i++) {
239 cnt = Map->
plus.
cidx[fi].type[i][1];
242 G_debug(3,
"%d tp = %d, cnt= %d count = %d", i, tp, cnt, count);
262 int cat_index,
int *cat,
int *type,
int *
id)
265 check_index(Map, field_index);
267 if (cat_index < 0 || cat_index >= Map->
plus.
cidx[field_index].n_cats)
270 *cat = Map->
plus.
cidx[field_index].cat[cat_index][0];
271 *type = Map->
plus.
cidx[field_index].cat[cat_index][1];
272 *
id = Map->
plus.
cidx[field_index].cat[cat_index][2];
293 check_index(Map, field_index);
295 ci = &(Map->
plus.
cidx[field_index]);
303 for (c = 1; c < ci->
n_cats; c++) {
304 if (ci->
cat[c][0] != ci->
cat[c - 1][0])
326 int type_mask,
int start_index,
int *
type,
int *
id)
332 "Vect_cidx_find_next() cat = %d, type_mask = %d, start_index = %d",
333 cat, type_mask, start_index);
336 check_index(Map, field_index);
340 ci = &(Map->
plus.
cidx[field_index]);
342 cat_index = ci_search_cat(ci, start_index, cat);
343 G_debug(3,
"cat_index = %d", cat_index);
349 G_debug(3,
" cat_index = %d", cat_index);
350 if (ci->
cat[cat_index][0] == cat && ci->
cat[cat_index][1] & type_mask) {
351 *type = ci->
cat[cat_index][1];
352 *
id = ci->
cat[cat_index][2];
353 G_debug(3,
" type match -> record found");
357 }
while (cat_index < ci->
n_cats);
377 int field_index, idx;
382 if (field_index == -1) {
386 ci = &(Map->
plus.
cidx[field_index]);
392 type_mask, 0, &type, &line);
399 if (ci->
cat[idx][0] != cat) {
402 if (ci->
cat[idx][1] & type_mask) {
406 }
while (idx < ci->
n_cats);
421 int i,
field, nfields, ntypes;
423 G_debug(2,
"Vect_cidx_dump()");
428 fprintf(out,
"---------- CATEGORY INDEX DUMP: Number of layers: %d " 429 "--------------------------------------\n", nfields);
431 for (i = 0; i < nfields; i++) {
432 int j, nucats, ncats;
440 "Layer %6d number of unique cats: %7d number of " 441 "cats: %7d number of types: %d\n",
442 field, nucats, ncats, ntypes);
445 fprintf(out,
" type | count\n");
446 for (j = 0; j < ntypes; j++) {
450 fprintf(out,
" %5d | %9d\n", type, count);
453 fprintf(out,
" category | type | line/area\n");
454 for (j = 0; j < ncats; j++) {
458 fprintf(out,
"%9d | %4d | %9d\n", cat, type,
id);
481 G_debug(2,
"Vect_cidx_save()");
491 G_warning(
_(
"Unable to create category index file for vector map <%s>"),
500 G_warning(
_(
"Error writing out category index file"));
526 G_debug(2,
"Vect_cidx_open(): name = %s mapset= %s", Map->
name,
534 if (access(file_path, F_OK) != 0) {
542 G_warning(
_(
"Unable to open category index file for vector map <%s>"),
553 G_debug(3,
"Cannot read cidx");
char * name
Map name (for 4.0)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
struct Version_info cidx
Version info for category index file.
char * Vect__get_element_path(char *file_path, const struct Map_info *Map, const char *element)
Get map element full path (internal use only)
void dig_init_portable(struct Port_info *, int)
Set Port_info structure to byte order of file.
int Vect_cidx_find_next(const struct Map_info *Map, int field_index, int cat, int type_mask, int start_index, int *type, int *id)
Find next line/area id for given category, start_index and type_mask.
int Vect_reset_list(struct ilist *)
Reset ilist structure.
int Vect_cidx_get_field_index(const struct Map_info *Map, int field)
Get layer index for given layer number.
int n_values
Number of values in the list.
int Vect_cidx_get_num_fields(const struct Map_info *Map)
Get number of layers in category index.
int field
Field (layer) number.
void dig_cidx_sort(struct Plus_head *)
int n_ucats
Number of unique cats (not updated)
int cidx_up_to_date
Category index to be updated.
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
Basic topology-related info.
#define GV_CIDX_ELEMENT
Native format, category index.
int Vect_cidx_get_cat_by_index(const struct Map_info *Map, int field_index, int cat_index, int *cat, int *type, int *id)
Get category, feature type and id for given layer and category index.
int Vect_cidx_get_num_cats_by_index(const struct Map_info *Map, int index)
Get number of categories for given layer index.
int n_cats
Number of items in cat array.
int Vect_cidx_get_field_number(const struct Map_info *Map, int index)
Get layer number for given index.
struct Plus_head plus
Plus info (topology, version, ...)
void dig_file_init(struct gvfile *file)
Initialize gvfile strcuture.
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
int(* cat)[3]
Array of cats (cat, type, lines/area)
char * mapset
Mapset name.
int Vect_cidx_get_num_unique_cats_by_index(const struct Map_info *Map, int index)
Get number of unique categories for given layer index.
int Vect_cidx_get_num_types_by_index(const struct Map_info *Map, int field_index)
Get number of feature types for given layer index.
int type[7][2]
Number of elements for each type.
int Vect_cidx_get_unique_cats_by_index(struct Map_info *Map, int field_index, struct ilist *list)
Get list of unique categories for given layer index.
FILE * file
File descriptor.
int dig__byte_order_out()
Get byte order.
const char * Vect_get_full_name(const struct Map_info *)
Get fully qualified name of vector map.
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
void G_warning(const char *,...) __attribute__((format(printf
int Vect_cidx_save(struct Map_info *Map)
Save category index to binary file (cidx)
int Vect_cidx_open(struct Map_info *Map, int head_only)
Read category index from cidx file if exists.
int dig_write_cidx(struct gvfile *, struct Plus_head *)
int dig_read_cidx(struct gvfile *, struct Plus_head *, int)
Read spatial index file.
char * Vect__get_path(char *path, const struct Map_info *Map)
Get map directory name (internal use only)
struct Port_info cidx_port
Portability information for category index.
int Vect_cidx_get_type_count_by_index(const struct Map_info *Map, int field_index, int type_index, int *type, int *count)
Get count of feature types for given field and type index.
const char * Vect_get_name(const struct Map_info *)
Get name of vector map.
int G_debug(int, const char *,...) __attribute__((format(printf
int Vect_cidx_dump(const struct Map_info *Map, FILE *out)
Write (dump) category index in text form to file.
int Vect_cidx_get_type_count(const struct Map_info *Map, int field, int type)
Get count of features of certain type by layer and type.
int n_cidx
Number of category indexes (one for each field/layer)
void Vect_cidx_find_all(const struct Map_info *Map, int layer, int type_mask, int cat, struct ilist *lines)
Find all line/area id's for given category.