GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
Vlib/cindex.c File Reference

Vector library - category index management. More...

#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <grass/vector.h>
#include <grass/glocale.h>
#include "local_proto.h"
Include dependency graph for Vlib/cindex.c:

Go to the source code of this file.

Macros

#define SEP   "------------------------------------------------------------------------------------------\n"
 

Functions

int Vect_cidx_get_num_fields (const struct Map_info *Map)
 Get number of layers in category index. More...
 
int Vect_cidx_get_field_number (const struct Map_info *Map, int index)
 Get layer number for given index. More...
 
int Vect_cidx_get_field_index (const struct Map_info *Map, int field)
 Get layer index for given layer number. More...
 
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. More...
 
int Vect_cidx_get_num_cats_by_index (const struct Map_info *Map, int index)
 Get number of categories for given layer index. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int Vect_cidx_dump (const struct Map_info *Map, FILE *out)
 Write (dump) category index in text form to file. More...
 
int Vect_cidx_save (struct Map_info *Map)
 Save category index to binary file (cidx) More...
 
int Vect_cidx_open (struct Map_info *Map, int head_only)
 Read category index from cidx file if exists. More...
 

Detailed Description

Vector library - category index management.

Higher level functions for reading/writing/manipulating vectors.

(C) 2001-2013 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Radim Blazek
Some contribution by Martin Landa <landa.martin gmail.com>

Definition in file Vlib/cindex.c.

Macro Definition Documentation

◆ SEP

#define SEP   "------------------------------------------------------------------------------------------\n"

Definition at line 27 of file Vlib/cindex.c.

Function Documentation

◆ Vect_cidx_dump()

int Vect_cidx_dump ( const struct Map_info Map,
FILE *  out 
)

Write (dump) category index in text form to file.

Parameters
Mappointer to Map_info structure
[out]outoutput file
Returns
1 on success
0 on error

Definition at line 419 of file Vlib/cindex.c.

References Cat_index::field, and G_debug().

◆ Vect_cidx_find_all()

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.

Parameters
Mappointer to Map_info structure
layerlayer number
type_maskfeature type of objects to search for
catcategory number
[out]linesarray of ids of found lines/points

Definition at line 372 of file Vlib/cindex.c.

◆ Vect_cidx_find_next()

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.

Parameters
Mappointer to Map_info structure
field_indexlayer index
catcategory number
type_maskrequested feature type
start_indexstart search at this index (0 - whole category index)
[out]typereturned type
[out]idreturned line/area id
Returns
index to array
-1 not found

Definition at line 325 of file Vlib/cindex.c.

◆ Vect_cidx_get_cat_by_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.

Parameters
Mappointer to Map_info structure
field_indexlayer index
cat_indexcategory index
[out]catcategory number
[out]typefeature type
[out]idfeature id
Returns
1 on success
0 on error

Definition at line 261 of file Vlib/cindex.c.

◆ Vect_cidx_get_field_index()

int Vect_cidx_get_field_index ( const struct Map_info Map,
int  field 
)

Get layer index for given layer number.

Parameters
Mappointer to Map_info structure
fieldlayer number
Returns
layer index
-1 if not found

Definition at line 113 of file Vlib/cindex.c.

References G_debug().

◆ Vect_cidx_get_field_number()

int Vect_cidx_get_field_number ( const struct Map_info Map,
int  index 
)

Get layer number for given index.

G_fatal_error() is called when index not found.

Parameters
Mappointer to Map_info structure
indexlayer index: from 0 to Vect_cidx_get_num_fields() - 1
Returns
layer number

Definition at line 96 of file Vlib/cindex.c.

◆ Vect_cidx_get_num_cats_by_index()

int Vect_cidx_get_num_cats_by_index ( const struct Map_info Map,
int  index 
)

Get number of categories for given layer index.

Parameters
Mappointer to Map_info structure
indexlayer index
Returns
number of categories
-1 on error

Definition at line 159 of file Vlib/cindex.c.

◆ Vect_cidx_get_num_fields()

int Vect_cidx_get_num_fields ( const struct Map_info Map)

Get number of layers in category index.

Parameters
Mappointer to Map_info structure
Returns
number of layers

Definition at line 79 of file Vlib/cindex.c.

◆ Vect_cidx_get_num_types_by_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.

G_fatal_error() is called when index not found.

Parameters
Mappointer to Map_info structure
field_indexlayer index
Returns
number of feature types
-1 on error

Definition at line 178 of file Vlib/cindex.c.

◆ Vect_cidx_get_num_unique_cats_by_index()

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.

G_fatal_error() is called when index not found.

Parameters
Mappointer to Map_info structure
indexlayer index (starts at 0)
Returns
number of unique categories
-1 on error

Definition at line 142 of file Vlib/cindex.c.

◆ Vect_cidx_get_type_count()

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.

Parameters
Mappointer to Map_info structure
fieldlayer number
typefeature type
Returns
feature count
0 if no features, no such field or no such type in category index

Definition at line 221 of file Vlib/cindex.c.

◆ Vect_cidx_get_type_count_by_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.

Parameters
Mappointer to Map_info structure
field_indexlayer index
type_indextype index
[out]typefeature type (GV_POINT, ...)
[out]countnumber of features or NULL
Returns
1 on success
0 on error

Definition at line 198 of file Vlib/cindex.c.

◆ Vect_cidx_get_unique_cats_by_index()

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.

Parameters
Mappointer to Map_info structure
field_indexlayer index
[out]listoutput list of cats
Returns
1 on success
0 on error

Definition at line 287 of file Vlib/cindex.c.

◆ Vect_cidx_open()

int Vect_cidx_open ( struct Map_info Map,
int  head_only 
)

Read category index from cidx file if exists.

Parameters
Mappointer to Map_info structure
head_onlyread only header of the file
Returns
0 on success
1 if file does not exist
-1 error, file exists but cannot be read

Definition at line 519 of file Vlib/cindex.c.

References _, dig_file_init(), dig_read_cidx(), gvfile::file, G_debug(), G_fopen_old(), G_warning(), GPATH_MAX, GV_CIDX_ELEMENT, Map_info::mapset, Map_info::name, NULL, Map_info::plus, Vect__get_element_path(), Vect__get_path(), and Vect_get_full_name().

◆ Vect_cidx_save()

int Vect_cidx_save ( struct Map_info Map)

Save category index to binary file (cidx)

Parameters
Mappointer to Map_info structure
Returns
0 on success
1 on error

Definition at line 475 of file Vlib/cindex.c.

References G_debug(), and GPATH_MAX.