GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
field.c File Reference

Vector library - field(layer) related fns. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <grass/glocale.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
#include <grass/Vect.h>
#include <gdal_version.h>
#include <ogr_api.h>
Include dependency graph for field.c:

Go to the source code of this file.

Functions

struct dblinks * Vect_new_dblinks_struct (void)
 Create and init new dblinks ctructure. More...
 
void Vect_reset_dblinks (struct dblinks *p)
 Reset dblinks structure. More...
 
int Vect_map_add_dblink (struct Map_info *Map, int number, const char *name, const char *table, const char *key, const char *db, const char *driver)
 Add new db connection to Map_info structure. More...
 
int Vect_map_del_dblink (struct Map_info *Map, int field)
 Delete db connection from Map_info structure. More...
 
int Vect_map_check_dblink (struct Map_info *Map, int field)
 Check if db connection exists in dblinks structure. More...
 
int Vect_check_dblink (struct dblinks *p, int field)
 Check if db connection exists in dblinks structure. More...
 
int Vect_add_dblink (struct dblinks *p, int number, const char *name, const char *table, const char *key, const char *db, const char *driver)
 Add new db connection to dblinks structure. More...
 
struct field_info * Vect_default_field_info (struct Map_info *Map, int field, const char *field_name, int type)
 Get default information about link to database for new dblink. More...
 
struct field_info * Vect_get_dblink (struct Map_info *Map, int link)
 Get information about link to database. More...
 
struct field_info * Vect_get_field (struct Map_info *Map, int field)
 Get information about link to database. More...
 
int Vect_read_dblinks (struct Map_info *Map)
 Read dblinks to existing structure. More...
 
int Vect_write_dblinks (struct Map_info *Map)
 Write dblinks to file. More...
 
char * Vect_subst_var (const char *in, struct Map_info *Map)
 Substitute variable in string. More...
 
void Vect_set_db_updated (struct Map_info *Map)
 Rewrite 'dbln' file. More...
 

Detailed Description

Vector library - field(layer) related fns.

Higher level functions for reading/writing/manipulating vectors.

TODO: see Vect_read_dblinks; activate auto-FID detection once OGR_L_GetFIDColumn() is working or solution found if FID not available

(C) 2001-2008 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
Original author CERL, probably Dave Gerdes or Mike Higgins. Update to GRASS 5.7 Radim Blazek and David D. Gray.
Date
2001-2008

Definition in file field.c.

Function Documentation

int Vect_add_dblink ( struct dblinks *  p,
int  number,
const char *  name,
const char *  table,
const char *  key,
const char *  db,
const char *  driver 
)

Add new db connection to dblinks structure.

Parameters
ppointer to existing dblinks structure
numberlayer number
namelayer name
keykey name
dbdatabase name
driverdriver name
Returns
0 OK
-1 error

Definition at line 214 of file field.c.

References G_debug(), G_store(), G_warning(), NULL, and Vect_check_dblink().

Referenced by Vect_map_add_dblink(), and Vect_read_dblinks().

int Vect_check_dblink ( struct dblinks *  p,
int  field 
)

Check if db connection exists in dblinks structure.

Parameters
ppointer to existing dblinks structure
fieldlayer number
Returns
1 dblink for field exists
0 dblink does not exist for field

Definition at line 185 of file field.c.

References G_debug().

Referenced by Vect_add_dblink(), and Vect_map_check_dblink().

struct field_info* Vect_default_field_info ( struct Map_info *  Map,
int  field,
const char *  field_name,
int  type 
)

Get default information about link to database for new dblink.

Parameters
Mapvector map
fieldlayer number
field_namelayer name
typehow many tables are linked to map: GV_1TABLE / GV_MTABLE
Returns
pointer to new field_info structure

Definition at line 278 of file field.c.

References buf, buf2, db_get_connection(), db_set_default_connection(), G__getenv2(), G_debug(), G_fatal_error(), G_store(), G_warning(), NULL, and sprintf().

Referenced by Vect_copy(), Vect_copy_table_by_cats(), Vect_copy_tables(), and Vect_rename().

struct field_info* Vect_get_dblink ( struct Map_info *  Map,
int  link 
)

Get information about link to database.

Variables are substituted by values, link is index to array of dblinks

Parameters
Mapvector map
linklink id
Returns
pointer to new field_info structure

Definition at line 364 of file field.c.

References G_debug(), G_store(), G_warning(), malloc(), NULL, and Vect_subst_var().

Referenced by wxdigit.IVDigit::DeleteSelectedLines(), wxdigit.IVDigit::InitCats(), Vect_copy(), Vect_copy_tables(), Vect_delete(), Vect_get_field(), and Vect_rename().

struct field_info* Vect_get_field ( struct Map_info *  Map,
int  field 
)

Get information about link to database.

Variables are substituted by values, field is number of requested field

Parameters
Mapvector map
fieldlayer number
Returns
pointer to new field_info structure
NULL if not found

Definition at line 404 of file field.c.

References G_debug(), NULL, and Vect_get_dblink().

Referenced by wxdigit.IVDigit::CopyCats(), G_sites_get_fields(), G_sites_open_old(), IL_vector_input_data_2d(), NetA_get_node_costs(), NetA_init_timetable_from_db(), Vect_copy_table_by_cats(), Vect_get_column_names(), Vect_get_column_names_types(), Vect_get_column_types(), Vect_net_build_graph(), Vect_rename(), and Vect_set_varray_from_db().

int Vect_map_add_dblink ( struct Map_info *  Map,
int  number,
const char *  name,
const char *  table,
const char *  key,
const char *  db,
const char *  driver 
)

Add new db connection to Map_info structure.

Parameters
Mapvector map
numberlayer number
namelayer name
tabletable name
keykey name
dbdatabase name
driverdriver name
Returns
0 OK
-1 error

Definition at line 86 of file field.c.

References G_warning(), Vect_add_dblink(), and Vect_write_dblinks().

Referenced by Vect_copy(), Vect_copy_table_by_cats(), Vect_copy_tables(), and Vect_rename().

int Vect_map_check_dblink ( struct Map_info *  Map,
int  field 
)

Check if db connection exists in dblinks structure.

Parameters
Mapvector map
fieldlayer number
Returns
1 dblink for field exists
0 dblink does not exist for field

Definition at line 171 of file field.c.

References Vect_check_dblink().

int Vect_map_del_dblink ( struct Map_info *  Map,
int  field 
)

Delete db connection from Map_info structure.

Parameters
Mapvector map
fieldlayer number
Returns
0 deleted
-1 error

Definition at line 125 of file field.c.

References G_debug(), G_warning(), and Vect_write_dblinks().

Referenced by Vect_rename().

struct dblinks* Vect_new_dblinks_struct ( void  )

Create and init new dblinks ctructure.

Parameters
void
Returns
pointer to new dblinks structure

Definition at line 45 of file field.c.

References NULL.

Referenced by Vect__open_old(), and Vect_open_new().

int Vect_read_dblinks ( struct Map_info *  Map)

Read dblinks to existing structure.

Variables are not substituted by values.

Parameters
Mapvector map
Returns
number of links read
-1 on error

Definition at line 431 of file field.c.

References buf, db_auto_print_errors(), db_close_cursor(), db_close_database_shutdown_driver(), db_init_string(), db_open_select_cursor(), db_set_string(), db_start_driver_open_database(), driver, FALSE, fclose(), fd, file, G_chop(), G_debug(), G_fatal_error(), G_free_tokens(), G_getl2(), G_number_of_tokens(), G_tokenize(), G_warning(), NULL, sprintf(), Vect_add_dblink(), and Vect_reset_dblinks().

Referenced by Vect__open_old().

void Vect_reset_dblinks ( struct dblinks *  p)

Reset dblinks structure.

Parameters
ppointer to existing dblinks structure
Returns
void

Definition at line 66 of file field.c.

Referenced by Vect_read_dblinks().

void Vect_set_db_updated ( struct Map_info *  Map)

Rewrite 'dbln' file.

Should be used by GRASS modules which update database tables, so that other applications know that tables were changed and can reload data.

Parameters
Mapvector map
Returns
void

Definition at line 801 of file field.c.

References G_fatal_error(), G_mapset(), and Vect_write_dblinks().

char* Vect_subst_var ( const char *  in,
struct Map_info *  Map 
)

Substitute variable in string.

Parameters
incurrent string
Mapvector map
Returns
pointer to new string

Definition at line 741 of file field.c.

References buf, G_debug(), G_free(), G_store(), G_str_replace(), NULL, and sprintf().

Referenced by Vect_copy(), Vect_copy_table_by_cats(), Vect_copy_tables(), Vect_get_dblink(), and Vect_rename().

int Vect_write_dblinks ( struct Map_info *  Map)

Write dblinks to file.

Parameters
Mapvector map
Returns
0 OK
-1 on error

Definition at line 690 of file field.c.

References buf, fclose(), fd, file, G_debug(), G_warning(), NULL, and sprintf().

Referenced by V1_close_nat(), Vect_map_add_dblink(), Vect_map_del_dblink(), and Vect_set_db_updated().