1v.db.connect(1)               Grass User's Manual              v.db.connect(1)
2
3
4

NAME

6       v.db.connect  - Prints/sets DB connection for a vector map to attribute
7       table.
8

KEYWORDS

10       vector, database, attribute table
11

SYNOPSIS

13       v.db.connect
14       v.db.connect help
15       v.db.connect [-pgcod] map=name  [driver=name]   [database=name]    [ta‐
16       ble=name]   [key=name]   [layer=integer]   [--verbose]  [--quiet]
17
18   Flags:
19       -p
20           Print all map connection parameters and exit
21
22       -g
23           Print all map connection parameters and exit in shell script style
24           Format: layer[/layer name] table key database driver
25
26       -c
27           Print types/names of table columns for specified layer and exit
28
29       -o
30           Overwrite connection parameter for certain layer
31
32       -d
33           Delete connection for certain layer (not the table)
34
35       --verbose
36           Verbose module output
37
38       --quiet
39           Quiet module output
40
41   Parameters:
42       map=name
43           Name of input vector map
44
45       driver=name
46           Driver name
47           Options: ogr,dbf,odbc,pg,mysql,sqlite,mesql
48           Default: dbf
49
50       database=name
51           Database name
52           Default: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/
53
54       table=name
55           Table name
56
57       key=name
58           Key column name
59           Must refer to an integer column
60           Default: cat
61
62       layer=integer
63           Layer number
64           A  single  vector map can be connected to multiple database tables.
65           This number determines which table to use.
66           Default: 1
67

DESCRIPTION

69       v.db.connect prints or sets database connection for a vector  map.  The
70       user can add or remove link to attribute table on the certain layer.
71

NOTE

73       If  parameters for database connection are already set with db.connect,
74       they are taken as default values and do not need to  be  spcified  each
75       time.
76
77       When  printing database connection (p or g flag) the parameter layer is
78       ignored, i.e. all connections are printed to the output.
79
80       Attention: Removing a vector map will also delete all tables linked  to
81       it!  If  you use v.db.connect to link further tables to your map, it is
82       advisable to make a copy from those tables first and connect the copied
83       tables to the vector map (see also v.overlay).
84

EXAMPLE

86   Print database connection
87       Print all database connection parameters for vector map.
88       v.db.connect -p map=roads
89
90
91       Print column types and names of table linked to vector map.
92       v.db.connect -c map=roads
93
94
95   Connect vector map to database (DBF driver)
96       Connect vector map to DBF table without or with variables.
97
98       Using default DB connection:
99       v.db.connect map=vectormap table=table
100
101
102       Using hardcoded path to DBF directory (not recommended):
103
104       v.db.connect   map=vectormap   table=table   database=/home/user/grass‐
105       data/spearfish60/PERMANENT/dbf
106
107
108       Using variable as DBF directory definition, single quotes must be used:
109
110       v.db.connect   map=vectormap   table=table   database='$GISDBASE/$LOCA‐
111       TION_NAME/$MAPSET/dbf/'
112
113
114       Connect vector map layer 2 and key ID to database with variables (note:
115       if needed, single quotes must be used for the database parameter):
116       v.db.connect map=vectormap table=table layer=2 key=ID
117
118
119   Connect vector map to database (MySQL driver)
120
121       # note: connection which requires password
122       db.connect driver=mysql database="host=dbserver.foo.org,dbname=my_data‐
123       base"
124       db.login user=joshua [password=xxx]
125       # ... or enter password interactively.
126       db.tables -p
127       # connect external table to layer 2:
128       v.db.connect map=my_map table=my_mysql_table key=baz layer=2
129       v.db.connect -p my_map
130
131
132   Connect vector map to database (PostgreSQL driver)
133
134       # note: connection without password being asked
135       v.db.connect map=vectormap table=table layer=1 key=oid driver=pg \
136                    database="host=myserver.itc.it,dbname=mydb,user=name" \
137                    table=mytable key=id
138
139
140   Store geometry in GRASS but attributes in PostgreSQL
141       This  example  illustrated  a  mixed  data storage with possibility top
142       update attributes in external PostgreSQL database:
143       # Check current settings for attribute storage:
144       db.connect -p
145       # Import table from PostgreSQL to new map
146       # (NOTE: output map name needs to be different from table name in
147       #        case that GRASS is connected to PostgreSQL):
148       v.in.db driver=pg database="host=localhost,dbname=meteo" \
149               table=mytable x=lon y=lat key=cat out=mytable
150       v.db.connect map=mytable -p
151       # Cancel table connection between map and attribute table:
152       v.db.connect map=mytable -d
153       v.db.connect map=mytable -p
154       # Drop table which was replicated due to import:
155       db.tables -p
156       echo "DROP TABLE mytable" | db.execute
157       db.tables -p
158       # reconnect map to table in PostgreSQL:
159       v.db.connect      map=mytable      driver=pg      database="host=local‐
160       host,dbname=meteo" \
161               table=mytable key=cat
162       # Now the geometry is stored in GRASS while the attributes are stored
163       # in PostgreSQL.
164        An alternative is to create a "view" of only ID, x, y [,z] columns and
165       to use v.in.db on this view, then connect the  original  table  to  the
166       geometry. This will be faster if the original table is very large.
167
168   Store geometry in GRASS but attributes in PostGIS
169       This  example  illustrated  a  mixed  data storage with possibility top
170       update attributes in external PostGIS database:
171       # Check current settings for attribute storage:
172       db.connect -p
173       # Import table from PostGIS to new map
174       # (NOTE: output map name needs to be different from table name in
175       #        case that GRASS is connected to PostGIS):
176       v.in.db driver=pg database="host=localhost,dbname=meteo" \
177               table=mytable x="x(geom)" y="y(geom)" key=cat out=mytable
178       v.db.connect map=mytable -p
179       # Cancel table connection between map and attribute table:
180       v.db.connect map=mytable -d
181       v.db.connect map=mytable -p
182       # Drop table which was replicated due to import:
183       db.tables -p
184       echo "DROP TABLE mytable" | db.execute
185       db.tables -p
186       # reconnect map to table in PostGIS:
187       v.db.connect      map=mytable      driver=pg      database="host=local‐
188       host,dbname=meteo" \
189               table=mytable key=cat
190       # Now the geometry is stored in GRASS while the attributes are stored
191       # in PostGIS.
192
193

SEE ALSO

195       db.connect,    db.copy,   db.tables,   v.db.addtable,   v.db.droptable,
196       v.db.addcol, v.db.dropcol, v.external, v.in.db, v.overlay
197

AUTHOR

199       Radim Blazek, ITC-Irst, Trento, Italy
200
201       Last changed: $Date: 2007-09-10 08:58:58 +0200 (Mon, 10 Sep 2007) $
202
203       Full index
204
205       © 2003-2008 GRASS Development Team
206
207
208
209GRASS 6.3.0                                                    v.db.connect(1)
Impressum