grass-odbc (1) - Linux Man PagesCommunication between GRASS and ODBC database for attribute management:
| GRASS module | | ODBC Interface | | RDBMS
| GRASS | DBMI driver | unixODBC | ODBC driver | PostgreSQL
Supported SQL commandsAll SQL commands supported by ODBC.
Operators available in conditionsAll SQL operators supported by ODBC.
EXAMPLEIn this example we copy the dbf file of a SHAPE map into ODBC, then connect GRASS to the ODBC DBMS. Usually the table will be already present in the DBMS.
Configure ODBC driver for selected database (manually or with 'ODBCConfig').
ODBC drivers are defined in /etc/odbcinst.ini. Here is example:
Description = ODBC for PostgreSQL
Driver = /usr/lib/libodbcpsql.so
Setup = /usr/lib/libodbcpsqlS.so
FileUsage = 1
Create DSN (data source name). The DSN is used as database name in db.* modules. Then DSN must be defined in $HOME/.odbc.ini (for this user only) or in /etc/odbc.ini for (for all users) [watch out for the database name which appears twice and also for the PostgreSQL protocol version]. Omit blanks at the beginning of lines:
Description = PostgreSQL
Driver = PostgreSQL
Trace = No
Database = grass6test
Servername = localhost
UserName = neteler
Port = 5432
Protocol = 8.0
ReadOnly = No
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No
ConnSettings = Configuration of an DSN without GUI is described on http://www.unixodbc.org/odbcinst.html, but odbc.ini and .odbc.ini may be created by the 'ODBCConfig' tool. You can easily view your DSN structure by 'DataManager'. Configuration with GUI is described on http://www.unixodbc.org/doc/UserManual/
To find out about your PostgreSQL protocol, run:
Now create a new database if not yet existing:
db.createdb driver=odbc database=grass6test
Now store the table 'mytable.dbf' (here: in current directory) into PostgreSQL
db.connect driver=odbc database=grass6test
db.copy from_driver=dbf from_database=./ from_table=mytable rs
to_driver=odbc to_database=grass6test to_table=mytable
Next link map to attribute table (now the ODBC table is used, not the dbf file):
v.db.connect map=mytable.shp table=mytable key=ID rs
Finally a test: Here we should see the table columns (if the ODBC connection works):
Now the table name 'mytable' should appear.
Doesn't work? Check with 'isql ' if the ODBC-PostgreSQL connection is really established.
- Configure ODBC driver for selected database (manually or with 'ODBCConfig'). ODBC drivers are defined in /etc/odbcinst.ini. Here is example:
v.db.connect -p mytable.shp
which should print the database connection through ODBC to the defined RDBMS.
SEE ALSOdb.connect, v.db.connect, unixODBC web site, SQL support in GRASS GIS
Last changed: $Date: 2007-07-18 16:10:27 +0200 (Wed, 18 Jul 2007) $