DB2 Spatial

This driver implements support for access to spatial tables in the IBM DB2 for Linux, Unix and Windows (DB2 LUW) and the IBM DB2 for z/OS relational databases using the default ODBC support incorporated into GDAL.

The documentation for the DB2 spatial features can be found online for DB2 for z/OS and DB2 LUW

This driver is currently supported only in the Windows environment.

Connecting to a database

To connect to a DB2 datasource, use a connection string specifying the database name, with additional parameters as necessary. The connection strings must be prefixed with 'DB2ODBC:'.
You can specify either a DSN that has been registered or use parameters that specify the host, port and protocol.
DB2ODBC:database=dbname;DRIVER={IBM DB2 ODBC DRIVER};Hostname=hostipaddr;PROTOCOL=TCPIP;port=db2port;UID=myuserid;PWD=mypw
The following custom parameters can also be used in the following syntax:

The parameter names are not case sensitive in the connection strings.

Specifying the Database parameter is required by the driver in order to select the proper database.


By default the DB2 driver will only look for layers that are registered in the DB2GSE.ST_GEOMETRY_COLUMNS metadata table.

SQL statements

The DB2 driver passes SQL statements directly to DB2 by default, rather than evaluating them internally when using the ExecuteSQL() call on the OGRDataSource, or the -sql command option to ogr2ogr. Attribute query expressions are also passed directly through to DB2. It's also possible to request the OGR DB2 driver to handle SQL commands with the OGR SQL engine, by passing "OGRSQL" string to the ExecuteSQL() method, as the name of the SQL dialect.

The DB2 driver in OGR supports the OGRLayer::StartTransaction(), OGRLayer::CommitTransaction() and OGRLayer::RollbackTransaction() calls in the normal SQL sense.

Creation Issues

This driver doesn't support creating new databases. Use the DB2 command line or tools like IBM Data Studio to create the database. It does allow creation of new layers within an existing database.

Layer Creation Options

Spatial Index Creation

By default the DB2 driver doesn't add spatial indexes to the tables during the layer creation. Spatial indexes should be created using the DB2 CREATE INDEX command.


Creating a layer from an OGR data source

ogr2ogr -overwrite  DB2ODBC:database=sample;DSN=sampDSN zipcodes.shp

Connecting to a layer and dump the contents

ogrinfo -al DB2ODBC:database=sample;DSN=sampDSN;tables=zipcodes