GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71785
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
field.c File Reference

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

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

Go to the source code of this file.

Functions

struct dblinksVect_new_dblinks_struct (void)
 Create and init new dblinks structure. More...
 
void Vect_reset_dblinks (struct dblinks *p)
 Reset dblinks structure (number of fields) 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...
 
void Vect_copy_map_dblinks (const struct Map_info *In, struct Map_info *Out, int first_only)
 Copy DB links from input vector map to output vector map. More...
 
int Vect_map_check_dblink (const struct Map_info *Map, int field, const char *name)
 Check if DB connection exists in dblinks structure. More...
 
int Vect_check_dblink (const struct dblinks *p, int field, const char *name)
 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_infoVect_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_infoVect_get_dblink (const struct Map_info *Map, int link)
 Get information about link to database. More...
 
struct field_infoVect_get_field (const struct Map_info *Map, int field)
 Get information about link to database (by layer number) More...
 
struct field_infoVect_get_field_by_name (const struct Map_info *Map, const char *field)
 Get information about link to database (by layer name) More...
 
struct field_infoVect_get_field2 (const struct Map_info *Map, const char *field)
 Get information about link to database (by layer number or layer name) More...
 
int Vect_get_field_number (const struct Map_info *Map, const char *field)
 Get field number of given field. 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, const 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-2009, 2011-2012 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 by Radim Blazek and David D. Gray.
Various updates by Martin Landa <landa.martin gmail.com>, 2009-2011

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
[in,out]ppointer to existing dblinks structure
numberlayer number (1 for OGR)
namelayer name (layer for OGR) - if not given use table name
tabletable name (layer for OGR)
keykey name
dbdatabase name (datasource for OGR)
driverdriver name (dbf, postgresql, ogr, ...)
Returns
0 on success
-1 error

Definition at line 248 of file field.c.

References _, dblinks::alloc_fields, field_info::database, field_info::driver, dblinks::field, G_debug(), G_store(), G_strchg(), G_warning(), field_info::key, dblinks::n_fields, field_info::name, NULL, field_info::number, field_info::table, and Vect_check_dblink().

Referenced by V1_close_nat(), and Vect_map_add_dblink().

int Vect_check_dblink ( const struct dblinks p,
int  field,
const char *  name 
)

Check if DB connection exists in dblinks structure.

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

Definition at line 215 of file field.c.

References dblinks::field, G_debug(), dblinks::n_fields, field_info::name, NULL, and field_info::number.

Referenced by Vect_add_dblink(), and Vect_map_check_dblink().

void Vect_copy_map_dblinks ( const struct Map_info In,
struct Map_info Out,
int  first_only 
)

Copy DB links from input vector map to output vector map.

Parameters
Inpointer to Map_info structure (input)
Outpointer to Map_info structure (output)
first_onlyTRUE to copy only first link otherwise all DB links are copied

Definition at line 168 of file field.c.

References _, field_info::database, field_info::driver, G_warning(), field_info::key, field_info::name, field_info::number, field_info::table, Vect_get_dblink(), Vect_get_num_dblinks(), and Vect_map_add_dblink().

Referenced by Vect_close().

struct field_info* Vect_default_field_info ( struct Map_info Map,
int  field,
const char *  field_name,
int  type 
)
struct field_info* Vect_get_dblink ( const 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
Mappointer to Map_info structure
linklink id
Returns
pointer to new field_info structure

Definition at line 421 of file field.c.

References _, field_info::database, Map_info::dblnk, field_info::driver, dblinks::field, G_debug(), G_store(), G_warning(), field_info::key, dblinks::n_fields, field_info::name, NULL, field_info::number, field_info::table, and Vect_subst_var().

Referenced by V1_close_nat(), Vect__delete(), Vect_copy_map_dblinks(), Vect_copy_tables(), Vect_get_field(), Vect_get_field2(), Vect_get_field_by_name(), and Vect_rename().

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

Get information about link to database (by layer number)

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

Parameters
Mappointer to Map_info structure
fieldlayer number
Returns
pointer to new field_info structure
NULL if not found

Definition at line 461 of file field.c.

References Map_info::dblnk, dblinks::field, G_debug(), dblinks::n_fields, NULL, field_info::number, and Vect_get_dblink().

Referenced by Gp_load_sites_thematic(), Gv_load_vect_thematic(), IL_vector_input_data_2d(), NetA_get_node_costs(), NetA_init_timetable_from_db(), Vect_cats_set_constraint(), Vect_copy_table_by_cats(), Vect_get_column_names(), Vect_get_column_names_types(), Vect_get_column_types(), Vect_get_field2(), Vect_net_build_graph(), Vect_net_ttb_build_graph(), Vect_rename(), Vect_set_varray_from_db(), and Vect_write_ascii().

struct field_info* Vect_get_field2 ( const struct Map_info Map,
const char *  field 
)

Get information about link to database (by layer number or layer name)

Note: if field is -1 then the function returns the first dblink or NULL

Parameters
Mappointer to Map_info structure
fieldlayer number or name
Returns
pointer to new field_info structure
NULL if not found

Definition at line 516 of file field.c.

References G_debug(), NULL, Vect_get_dblink(), Vect_get_field(), Vect_get_field_by_name(), and Vect_get_num_dblinks().

Referenced by Vect_get_field_number().

struct field_info* Vect_get_field_by_name ( const struct Map_info Map,
const char *  field 
)

Get information about link to database (by layer name)

Parameters
Mappointer to Map_info structure
fieldlayer name
Returns
pointer to new field_info structure
NULL if not found

Definition at line 487 of file field.c.

References Map_info::dblnk, dblinks::field, G_debug(), dblinks::n_fields, field_info::name, NULL, and Vect_get_dblink().

Referenced by Vect_get_field2().

int Vect_get_field_number ( const struct Map_info Map,
const char *  field 
)

Get field number of given field.

Parameters
Mappointer to Map_info structure
fieldlayer name
Returns
layer number
-1 for all layers
0 if layer not found

Definition at line 553 of file field.c.

References G_debug(), field_info::number, Vect_get_field2(), and Vect_get_num_dblinks().

Referenced by vector2perimeters().

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
Mappointer to Map_info structure
numberlayer number
namelayer name (if not given use table name)
tabletable name
keykey name
dbdatabase name
driverdriver name
Returns
0 on success
-1 on failure

Definition at line 84 of file field.c.

References _, Map_info::dblnk, G_warning(), GV_MODE_RW, GV_MODE_WRITE, Map_info::mode, Vect_add_dblink(), and Vect_write_dblinks().

Referenced by Vect_copy_map_dblinks(), Vect_copy_table_by_cats(), and Vect_rename().

int Vect_map_check_dblink ( const struct Map_info Map,
int  field,
const char *  name 
)

Check if DB connection exists in dblinks structure.

Parameters
Mappointer to Map_info structure
fieldlayer number
namelayer name
Returns
1 dblink for field exists
0 dblink does not exist for field

Definition at line 200 of file field.c.

References Map_info::dblnk, and Vect_check_dblink().

int Vect_map_del_dblink ( struct Map_info Map,
int  field 
)

Delete db connection from Map_info structure.

Parameters
Mappointer to Map_info structure
fieldlayer number (-1 to delete all dblinks)
Returns
0 deleted
-1 error

Definition at line 124 of file field.c.

References _, field_info::database, Map_info::dblnk, field_info::driver, dblinks::field, G_debug(), G_warning(), field_info::key, dblinks::n_fields, field_info::name, field_info::number, field_info::table, and Vect_write_dblinks().

Referenced by Vect_close(), and Vect_rename().

struct dblinks* Vect_new_dblinks_struct ( void  )

Create and init new dblinks structure.

Returns
pointer to new dblinks structure
NULL on failure

Definition at line 46 of file field.c.

References G_zero().

Referenced by V1_close_nat(), and Vect__open_old().

int Vect_read_dblinks ( struct Map_info Map)

Read dblinks to existing structure.

Variables are not substituted by values.

Parameters
Mappointer to Map_info structure
Returns
number of links read
-1 on error

Definition at line 875 of file field.c.

References _, Map_info::dblnk, Map_info::format, G_debug(), G_fatal_error(), GV_FORMAT_NATIVE, GV_FORMAT_OGR, GV_FORMAT_OGR_DIRECT, GV_FORMAT_POSTGIS, Map_info::mapset, Map_info::name, and Vect_reset_dblinks().

Referenced by Vect__open_old().

void Vect_reset_dblinks ( struct dblinks p)

Reset dblinks structure (number of fields)

Parameters
ppointer to existing dblinks structure

Definition at line 65 of file field.c.

References dblinks::n_fields.

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
Mappointer to Map_info structure

Definition at line 1016 of file field.c.

References _, G_fatal_error(), G_mapset(), G_strcasecmp(), Map_info::mapset, and Vect_write_dblinks().

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

Substitute variable in string.

Parameters
incurrent string
Mappointer to Map_info structure
Returns
pointer to new string

Definition at line 958 of file field.c.

References G_debug(), G_free(), G_store(), G_str_replace(), Map_info::gisdbase, Map_info::location, Map_info::mapset, Map_info::name, and NULL.

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