1v.db.connect(1) Grass 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, database, attribute table
11
13 v.db.connect
14 v.db.connect help
15 v.db.connect [-pgcod] map=name [driver=string] [database=string]
16 [table=string] [key=string] [layer=integer]
17
18 Flags:
19 -p Print current map connection parameters and exit
20
21 -g Print current map connection parameters and exit (shell script
22 style) format: layer[/layer name] table key database driver
23
24 -c Print types/names of table columns for specified layer and exit
25
26 -o Overwrite connection parameter for certain layer
27
28 -d Delete connection for certain layer (not the table)
29
30 Parameters:
31 map=name
32 Name of input vector map
33
34 driver=string
35 Driver name Options: dbf,mysql,ogr,pg,sqlite,mesql,odbc
36
37 database=string
38 Database name
39
40 table=string
41 Table name
42
43 key=string
44 Key name (must refer to an integer column) Default: cat
45
46 layer=integer
47 Layer number Default: 1
48
50 v.db.connect prints or sets database connection for a vector map.
51
53 If parameters for database connection are already set with db.connect,
54 they are taken as default values and do not need to be spcified each
55 time.
56
57 Attention: Removing a vector map will also delete all tables linked to
58 it! If you use v.db.connect to link further tables to your map, it is
59 advisable to make a copy from those tables first and connect the copied
60 tables to the vector map (see also v.overlay).
61
63 Print database connection
64
65 v.db.connect -p map=vectormap
66
67
68 Print column types and names of table linked to vector map
69
70 v.db.connect -c map=vectormap
71
72
73 Connect vector map to database (DBF driver)
74 Connect vector map to DBF table without or with variables
75 Using default DB connection:
76
77 v.db.connect map=vectormap table=table
78
79
80 Using hardcoded path to DBF directory (not recommended):
81
82 v.db.connect map=vectormap table=table database=/home/user/grass‐
83 data/spearfish60/PERMANENT/dbf
84
85
86 Using variable as DBF directory definition, single quotes must be used:
87
88 v.db.connect map=vectormap table=table database='$GISDBASE/$LOCA‐
89 TION_NAME/$MAPSET/dbf/'
90
91
92 Connect vector map layer 2 and key ID to database with variables
93 (note: if needed, single quotes must be used for the database parame‐
94 ter)
95
96 v.db.connect map=vectormap table=table layer=2 key=ID
97
98
99 Connect vector map to database (MySQL driver)
100
101 # note: connection which requires password
102 db.connect driver=mysql database="host=dbserver.foo.org,dbname=my_data‐
103 base"
104 db.login user=joshua [password=xxx]
105 # ... or enter password interactively.
106 db.tables -p
107 # connect external table to layer 2:
108 v.db.connect map=my_map table=my_mysql_table key=baz layer=2
109 v.db.connect -p my_map
110
111
112 Connect vector map to database (PostgreSQL driver)
113
114 # note: connection without password being asked
115 v.db.connect map=vectormap table=table layer=1 key=oid driver=pg \
116 database="host=myserver.itc.it,dbname=mydb,user=name" \
117 table=mytable key=id
118
119
120 Store geometry in GRASS but attributes in PostgreSQL
121 This example illustrated a mixed data storage with possibility top
122 update attributes in external PostgreSQL database:
123 # Check current settings for attribute storage:
124 db.connect -p
125 # Import table from PostgreSQL to new map
126 # (NOTE: output map name needs to be different from table name in
127 # case that GRASS is connected to PostgreSQL):
128 v.in.db driver=pg database="host=localhost,dbname=meteo" \
129 table=mytable x=lon y=lat key=cat out=mytable
130 v.db.connect map=mytable -p
131 # Cancel table connection between map and attribute table:
132 v.db.connect map=mytable -d
133 v.db.connect map=mytable -p
134 # Drop table which was replicated due to import:
135 db.tables -p
136 echo "DROP TABLE mytable" | db.execute
137 db.tables -p
138 # reconnect map to table in PostgreSQL:
139 v.db.connect map=mytable driver=pg database="host=local‐
140 host,dbname=meteo" \
141 table=mytable key=cat
142 # Now the geometry is stored in GRASS while the attributes are stored
143 # in PostgreSQL.
144 An alternative is to create a "view" of only ID, x, y [,z] columns and
145 to use v.in.db on this view, then connect the original table to the
146 geometry. This will be faster if the original table is very large.
147
148 Store geometry in GRASS but attributes in PostGIS
149 This example illustrated a mixed data storage with possibility top
150 update attributes in external PostGIS database:
151 # Check current settings for attribute storage:
152 db.connect -p
153 # Import table from PostGIS to new map
154 # (NOTE: output map name needs to be different from table name in
155 # case that GRASS is connected to PostGIS):
156 v.in.db driver=pg database="host=localhost,dbname=meteo" \
157 table=mytable x="x(geom)" y="y(geom)" key=cat out=mytable
158 v.db.connect map=mytable -p
159 # Cancel table connection between map and attribute table:
160 v.db.connect map=mytable -d
161 v.db.connect map=mytable -p
162 # Drop table which was replicated due to import:
163 db.tables -p
164 echo "DROP TABLE mytable" | db.execute
165 db.tables -p
166 # reconnect map to table in PostGIS:
167 v.db.connect map=mytable driver=pg database="host=local‐
168 host,dbname=meteo" \
169 table=mytable key=cat
170 # Now the geometry is stored in GRASS while the attributes are stored
171 # in PostGIS.
172
173
175 db.connect, db.copy, db.tables, v.db.addtable, v.external, v.in.db,
176 v.overlay,
177
179 Radim Blazek, ITC-Irst, Trento, Italy
180
181 Last changed: $Date: 2007/05/02 13:27:24 $
182
183 Full index
184
185
186
187GRASS 6.2.2 v.db.connect(1)