19 #include <sys/types.h>
25 #include "local_proto.h"
28 "------------------------------------------------------------------------" \
29 "------------------\n"
31 static void check_status(
struct Map_info *Map)
37 static void check_index(
struct Map_info *Map,
int index)
44 static int ci_search_cat(
struct Cat_index *ci,
int first,
int cat)
51 if (ci->
cat[lo][0] > cat)
53 if (ci->
cat[lo][0] == cat)
63 if (ci->
cat[mid][0] < cat)
68 if (ci->
cat[lo][0] == cat)
101 check_index(Map, index);
120 G_debug(2,
"Vect_cidx_get_field_index() field = %d", field);
125 for (i = 0; i < Plus->
n_cidx; i++) {
126 if (Plus->
cidx[i].field == field)
147 check_index(Map, index);
149 return Map->
plus.
cidx[index].n_ucats;
164 check_index(Map, index);
166 return Map->
plus.
cidx[index].n_cats;
183 check_index(Map, field_index);
185 return Map->
plus.
cidx[field_index].n_types;
201 int type_index,
int *type,
int *
count)
204 check_index(Map, field_index);
206 *type = Map->
plus.
cidx[field_index].type[type_index][0];
225 int i, fi,
count = 0;
227 G_debug(3,
"Vect_cidx_get_type_count() field = %d, type = %d", field, type);
233 G_debug(3,
"field_index = %d", fi);
236 for (i = 0; i < Map->
plus.
cidx[fi].n_types; i++) {
240 cnt = Map->
plus.
cidx[fi].type[i][1];
243 G_debug(3,
"%d tp = %d, cnt= %d count = %d", i, tp, cnt,
count);
263 int cat_index,
int *cat,
int *type,
int *
id)
266 check_index(Map, field_index);
268 if (cat_index < 0 || cat_index >= Map->
plus.
cidx[field_index].n_cats)
271 *cat = Map->
plus.
cidx[field_index].cat[cat_index][0];
272 *type = Map->
plus.
cidx[field_index].cat[cat_index][1];
273 *
id = Map->
plus.
cidx[field_index].cat[cat_index][2];
295 check_index(Map, field_index);
297 ci = &(Map->
plus.
cidx[field_index]);
305 for (c = 1; c < ci->
n_cats; c++) {
306 if (ci->
cat[c][0] != ci->
cat[c - 1][0])
328 int type_mask,
int start_index,
int *
type,
int *
id)
334 "Vect_cidx_find_next() cat = %d, type_mask = %d, start_index = %d",
335 cat, type_mask, start_index);
338 check_index(Map, field_index);
342 ci = &(Map->
plus.
cidx[field_index]);
344 cat_index = ci_search_cat(ci, start_index,
cat);
345 G_debug(3,
"cat_index = %d", cat_index);
351 G_debug(3,
" cat_index = %d", cat_index);
352 if (ci->
cat[cat_index][0] ==
cat && ci->
cat[cat_index][1] & type_mask) {
354 *
id = ci->
cat[cat_index][2];
355 G_debug(3,
" type match -> record found");
359 }
while (cat_index < ci->
n_cats);
378 int field_index, idx;
383 if (field_index == -1) {
387 ci = &(Map->
plus.
cidx[field_index]);
400 if (ci->
cat[idx][0] !=
cat) {
403 if (ci->
cat[idx][1] & type_mask) {
407 }
while (idx < ci->
n_cats);
422 int i,
field, nfields, ntypes;
424 G_debug(2,
"Vect_cidx_dump()");
430 "---------- CATEGORY INDEX DUMP: Number of layers: %d "
431 "--------------------------------------\n",
434 for (i = 0; i < nfields; i++) {
435 int j, nucats, ncats;
443 "Layer %6d number of unique cats: %7d number of "
444 "cats: %7d number of types: %d\n",
445 field, nucats, ncats, ntypes);
448 fprintf(out,
" type | count\n");
449 for (j = 0; j < ntypes; j++) {
453 fprintf(out,
" %5d | %9d\n",
type,
count);
456 fprintf(out,
" category | type | line/area\n");
457 for (j = 0; j < ncats; j++) {
461 fprintf(out,
"%9d | %4d | %9d\n",
cat,
type,
id);
484 G_debug(2,
"Vect_cidx_save()");
494 G_warning(
_(
"Unable to create category index file for vector map <%s>"),
503 G_warning(
_(
"Error writing out category index file"));
529 G_debug(2,
"Vect_cidx_open(): name = %s mapset= %s", Map->
name,
537 if (access(file_path, F_OK) != 0) {
545 G_warning(
_(
"Unable to open category index file for vector map <%s>"),
556 G_debug(3,
"Cannot read cidx");
int Vect_cidx_get_type_count_by_index(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.
int Vect_cidx_get_num_types_by_index(struct Map_info *Map, int field_index)
Get number of feature types for given layer index.
int Vect_cidx_open(struct Map_info *Map, int head_only)
Read category index from cidx file if exists.
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.
int Vect_cidx_find_next(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_cidx_get_num_cats_by_index(struct Map_info *Map, int index)
Get number of categories for given layer index.
int Vect_cidx_get_type_count(struct Map_info *Map, int field, int type)
Get count of features of certain type by layer and type.
int Vect_cidx_get_field_index(struct Map_info *Map, int field)
Get layer index for given layer number.
int Vect_cidx_save(struct Map_info *Map)
Save category index to binary file (cidx)
int Vect_cidx_get_cat_by_index(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_field_number(struct Map_info *Map, int index)
Get layer number for given index.
void Vect_cidx_find_all(struct Map_info *Map, int layer, int type_mask, int cat, struct ilist *lines)
Find all line/area id's for given category.
int Vect_cidx_dump(struct Map_info *Map, FILE *out)
Write (dump) category index in text form to file.
int Vect_cidx_get_num_fields(struct Map_info *Map)
Get number of layers in category index.
int Vect_cidx_get_num_unique_cats_by_index(struct Map_info *Map, int index)
Get number of unique categories for given layer index.
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
const char * Vect_get_full_name(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.
const char * Vect_get_name(struct Map_info *)
Get name of vector map.
int Vect_reset_list(struct ilist *)
Reset ilist structure.
#define GV_CIDX_ELEMENT
Native format, category index.
int dig_write_cidx(struct gvfile *, struct Plus_head *)
int dig__byte_order_out(void)
Get byte order.
int dig_read_cidx(struct gvfile *, struct Plus_head *, int)
Read spatial index file.
void dig_init_portable(struct Port_info *, int)
Set Port_info structure to byte order of file.
void dig_cidx_sort(struct Plus_head *)
void dig_file_init(struct gvfile *file)
Initialize gvfile structure.
int(* cat)[3]
Array of cats (cat, type, lines/area)
int n_cats
Number of items in cat array.
int field
Field (layer) number.
int type[7][2]
Number of elements for each type.
int n_ucats
Number of unique cats (not updated)
char * mapset
Mapset name.
char * name
Map name (for 4.0)
struct Plus_head plus
Plus info (topology, version, ...)
Basic topology-related info.
int n_cidx
Number of category indexes (one for each field/layer)
struct Port_info cidx_port
Portability information for category index.
int cidx_up_to_date
Category index to be updated.
struct Version_info cidx
Version info for category index file.
FILE * file
File descriptor.
char * Vect__get_path(char *path, struct Map_info *Map)
Get map directory name (internal use only)
char * Vect__get_element_path(char *file_path, struct Map_info *Map, const char *element)
Get map element full path (internal use only)