GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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 <gdal_version.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

◆ Vect_add_dblink()

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 277 of file field.c.

◆ Vect_check_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 244 of file field.c.

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

Referenced by Vect_map_check_dblink().

◆ Vect_copy_map_dblinks()

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 197 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().

◆ Vect_default_field_info()

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
Mappointer to Map_info structure
fieldlayer number
field_namelayer name
typehow many tables are linked to map: GV_1TABLE / GV_MTABLE
Returns
pointer to allocated field_info structure

Definition at line 351 of file field.c.

◆ Vect_get_dblink()

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 466 of file field.c.

References _, field_info::database, Map_info::dblnk, field_info::driver, dblinks::field, G_debug(), G_malloc, 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 Vect_copy_map_dblinks(), Vect_get_field(), Vect_get_field2(), and Vect_get_field_by_name().

◆ Vect_get_field()

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 506 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 Vect_cats_set_constraint(), and Vect_get_field2().

◆ Vect_get_field2()

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 561 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().

◆ Vect_get_field_by_name()

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 532 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().

◆ Vect_get_field_number()

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 598 of file field.c.

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

Referenced by vector2perimeters().

◆ Vect_map_add_dblink()

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 113 of file field.c.

Referenced by Vect_copy_map_dblinks().

◆ Vect_map_check_dblink()

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 229 of file field.c.

References Map_info::dblnk, and Vect_check_dblink().

◆ Vect_map_del_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 153 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().

◆ Vect_new_dblinks_struct()

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_malloc, and G_zero().

◆ Vect_read_dblinks()

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 920 of file field.c.

References Map_info::dblnk, Map_info::format, G_debug(), GV_FORMAT_NATIVE, Map_info::mapset, Map_info::name, and Vect_reset_dblinks().

◆ Vect_reset_dblinks()

void Vect_reset_dblinks ( struct dblinks p)

Reset dblinks structure (number of fields)

Parameters
ppointer to existing dblinks structure

Definition at line 94 of file field.c.

References dblinks::n_fields.

Referenced by Vect_read_dblinks().

◆ Vect_set_db_updated()

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 1061 of file field.c.

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

◆ Vect_subst_var()

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 1003 of file field.c.

Referenced by Vect_get_dblink().

◆ Vect_write_dblinks()