GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72636
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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

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

Referenced by Vect_cidx_dump().

Function Documentation

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 416 of file Vlib/cindex.c.

References cat, count, Cat_index::field, G_debug(), SEP, Cat_index::type, Vect_cidx_get_cat_by_index(), Vect_cidx_get_field_number(), Vect_cidx_get_num_cats_by_index(), Vect_cidx_get_num_fields(), Vect_cidx_get_num_types_by_index(), Vect_cidx_get_num_unique_cats_by_index(), and Vect_cidx_get_type_count_by_index().

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.

References Cat_index::cat, Plus_head::cidx, Cat_index::n_cats, Map_info::plus, Cat_index::type, Vect_cidx_find_next(), Vect_cidx_get_field_index(), Vect_list_append(), and Vect_reset_list().

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.

References Cat_index::cat, Plus_head::cidx, G_debug(), Cat_index::n_cats, and Map_info::plus.

Referenced by Vect_cidx_find_all(), and Vect_net_ttb_build_graph().

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.

References _, Plus_head::cidx, G_fatal_error(), and Map_info::plus.

Referenced by Vect_cidx_dump().

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 Plus_head::cidx, G_debug(), Plus_head::n_cidx, and Map_info::plus.

Referenced by Vect_cidx_find_all(), Vect_cidx_get_type_count(), and Vect_net_ttb_build_graph().

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.

References Plus_head::cidx, and Map_info::plus.

Referenced by Vect_cidx_dump().

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.

References Plus_head::cidx, and Map_info::plus.

Referenced by Vect_cidx_dump().

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.

References Plus_head::n_cidx, and Map_info::plus.

Referenced by Vect_cidx_dump().

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.

References Plus_head::cidx, and Map_info::plus.

Referenced by Vect_cidx_dump().

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.

References Plus_head::cidx, and Map_info::plus.

Referenced by Vect_cidx_dump().

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.

References Plus_head::cidx, count, G_debug(), Map_info::plus, and Vect_cidx_get_field_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.

References Plus_head::cidx, and Map_info::plus.

Referenced by Vect_cidx_dump().

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.

References Cat_index::cat, Plus_head::cidx, dig_cidx_sort(), Cat_index::n_cats, Cat_index::n_ucats, ilist::n_values, Map_info::plus, Vect_list_append(), and Vect_reset_list().

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 516 of file Vlib/cindex.c.

References _, dig_file_init(), dig_read_cidx(), fclose(), 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().

Referenced by Vect__open_old().

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 472 of file Vlib/cindex.c.

References _, Plus_head::cidx_port, dig__byte_order_out(), dig_file_init(), dig_init_portable(), dig_write_cidx(), fclose(), gvfile::file, G_debug(), G_fopen_new(), G_warning(), GPATH_MAX, GV_CIDX_ELEMENT, NULL, Map_info::plus, Vect__get_path(), and Vect_get_name().

Referenced by Vect_close().