1v.db.connect(1) GRASS GIS User's Manual v.db.connect(1)
2
3
4
6 v.db.connect - Prints/sets DB connection for a vector map to attribute
7 table.
8
10 vector, attribute table, database, layer
11
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=string] [separator=character]
17 [--overwrite] [--help] [--verbose] [--quiet] [--ui]
18
19 Flags:
20 -p
21 Print all map connection parameters and exit
22
23 -g
24 Print all map connection parameters in shell script style and exit
25 Format: layer[/layer name] table key database driver
26
27 -c
28 Print types/names of table columns for specified layer and exit
29
30 -o
31 Overwrite connection parameter for certain layer
32
33 -d
34 Delete connection for certain layer (not the table)
35
36 --overwrite
37 Allow output files to overwrite existing files
38
39 --help
40 Print usage summary
41
42 --verbose
43 Verbose module output
44
45 --quiet
46 Quiet module output
47
48 --ui
49 Force launching GUI dialog
50
51 Parameters:
52 map=name [required]
53 Name of vector map
54 Or data source for direct OGR access
55
56 driver=name
57 Name of database driver
58 Options: dbf, mesql, mysql, odbc, ogr, pg, sqlite
59 Default: sqlite
60
61 database=name
62 Name of database
63 Default: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
64
65 table=name
66 Name of attribute table
67
68 key=name
69 Name of key column
70 Must refer to an integer column
71 Default: cat
72
73 layer=string
74 Layer number or name
75 Format: layer number[/layer name]
76 Default: 1
77
78 separator=character
79 Field separator for shell script style output
80 Special characters: pipe, comma, space, tab, newline
81 Default: pipe
82
84 v.db.connect prints or sets database connection for a vector map. The
85 user can add or remove link to attribute table on the certain layer.
86
88 Connection information (driver, database, table, key) is stored for
89 each map, in the file
90 <database>/<location>/<mapset>/vector/<map>/dbln
91
92 If parameters for database connection are already set with db.connect,
93 they are taken as default values and do not need to be specified each
94 time.
95
96 When printing database connection (p or g flag) the parameter layer is
97 ignored, i.e. all connections are printed to the output.
98
99 Attention: Removing a vector map will also delete all tables linked to
100 it! If you use v.db.connect to link further tables to your map, it is
101 advisable to make a copy from those tables first and connect the copied
102 tables to the vector map (see also v.overlay).
103
105 Note: The default database backend setting is SQLite.
106
107 Print database connection
108 Print all database connection parameters for vector map.
109 v.db.connect -p map=roads
110
111 Print column types and names of table linked to vector map.
112 v.db.connect -c map=roads
113
114 Connect vector map to database (DBF driver)
115 Connect vector map to DBF table without or with variables.
116
117 Using default DB connection:
118 v.db.connect map=vectormap table=table
119
120 Using hardcoded path to DBF directory (not recommended):
121 v.db.connect map=vectormap table=table \
122 database=/home/user/grassdata/spearfish60/PERMANENT/dbf
123
124 Using variable as DBF directory definition, single quotes must be used:
125 v.db.connect map=vectormap table=table \
126 database=’$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/’
127
128 Connect vector map layer 2 and key ID to database with variables (note:
129 if needed, single quotes must be used for the database parameter):
130 v.db.connect map=vectormap table=table layer=2 key=ID
131
132 Connect vector map to database (SQLite driver)
133 Very similar to DBF driver example above.
134 db.connect driver=sqlite database=’$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db’
135 db.tables -p
136 v.db.connect map=vectormap table=table driver=sqlite \
137 database=’$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db’
138 v.db.connect -p map=vectormap
139
140 Connect vector map to database (MySQL driver)
141 # note: connection which requires password
142 db.connect driver=mysql database="host=dbserver.foo.org,dbname=my_database"
143 db.login user=joshua [password=xxx]
144 # ... or enter password interactively.
145 db.tables -p
146 # connect external table to layer 2:
147 v.db.connect map=my_map table=my_mysql_table key=baz layer=2
148 v.db.connect -p my_map
149
150 Connect vector map to database (PostgreSQL driver)
151 # note: connection without password being asked
152 v.db.connect map=vectormap table=table layer=1 key=oid driver=pg \
153 database="host=myserver.itc.it,dbname=mydb,user=name" \
154 table=mytable key=id
155
156 Store geometry in GRASS but attributes in PostgreSQL
157 This example illustrates a mixed data storage with possibility to up‐
158 date attributes in an external PostgreSQL database:
159 # Check current settings for attribute storage:
160 db.connect -p
161 # Import table from PostgreSQL to new map
162 # (NOTE: output map name needs to be different from table name in
163 # case that GRASS is connected to PostgreSQL):
164 v.in.db driver=pg database="host=localhost,dbname=meteo" \
165 table=mytable x=lon y=lat key=cat out=mytable
166 v.db.connect map=mytable -p
167 # Cancel table connection between map and attribute table:
168 v.db.connect map=mytable -d
169 v.db.connect map=mytable -p
170 # Drop table which was replicated due to import:
171 db.tables -p
172 echo "DROP TABLE mytable" | db.execute
173 db.tables -p
174 # reconnect map to table in PostgreSQL:
175 v.db.connect map=mytable driver=pg database="host=localhost,dbname=meteo" \
176 table=mytable key=cat
177 # Now the geometry is stored in GRASS while the attributes are stored
178 # in PostgreSQL.
179 An alternative is to create a "view" of only ID, x, y [,z] columns and
180 to use v.in.db on this view, then connect the original table to the ge‐
181 ometry. This will be faster if the original table is very large.
182
183 Store geometry in GRASS but attributes in PostGIS
184 This example illustrated a mixed data storage with possibility top up‐
185 date attributes in external PostGIS database:
186 # Check current settings for attribute storage:
187 db.connect -p
188 # Import table from PostGIS to new map
189 # (NOTE: output map name needs to be different from table name in
190 # case that GRASS is connected to PostGIS):
191 v.in.db driver=pg database="host=localhost,dbname=meteo" \
192 table=mytable x="x(geom)" y="y(geom)" key=cat out=mytable
193 v.db.connect map=mytable -p
194 # Cancel table connection between map and attribute table:
195 v.db.connect map=mytable -d
196 v.db.connect map=mytable -p
197 # Drop table which was replicated due to import:
198 db.tables -p
199 echo "DROP TABLE mytable" | db.execute
200 db.tables -p
201 # reconnect map to table in PostGIS:
202 v.db.connect map=mytable driver=pg database="host=localhost,dbname=meteo" \
203 table=mytable key=cat
204 # Now the geometry is stored in GRASS while the attributes are stored
205 # in PostGIS.
206
208 db.connect, db.copy, db.tables, v.db.addtable, v.db.droptable,
209 v.db.addcolumn, v.db.dropcolumn, v.external, v.in.db, v.overlay
210
211 GRASS SQL interface
212
214 Radim Blazek, ITC-Irst, Trento, Italy
215
217 Available at: v.db.connect source code (history)
218
219 Accessed: Saturday Jan 21 20:39:44 2023
220
221 Main index | Vector index | Topics index | Keywords index | Graphical
222 index | Full index
223
224 © 2003-2023 GRASS Development Team, GRASS GIS 8.2.1 Reference Manual
225
226
227
228GRASS 8.2.1 v.db.connect(1)