drv_db2.html 5.01 KB
Newer Older
xuebingbing's avatar
xuebingbing committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
<html>
<head>
<title>DB2 Spatial</title>
</head>

<body bgcolor="#ffffff">

<h1>DB2 Spatial</h1>

<p>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.
</p>
<p>
The documentation for the DB2 spatial features can be found online
for
<a href="http://www-01.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/com.ibm.db2z11.doc.spatl/src/spatl/dasz_spatl.dita?lang=en">
DB2 for z/OS</a>
and
<a href="http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.spatial.topics.doc/doc/db2sb03.html">
DB2 LUW</a>
<p>
This driver is currently supported only in the Windows environment.
</p>
<h2>Connecting to a database</h2>

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 &#39;<i>DB2ODBC:</i>&#39;.<br>
You can specify either a DSN that has been registered or use parameters that
specify the host, port and protocol.
<blockquote><pre>
DB2ODBC:database=dbname;DSN=datasourcename</pre></blockquote>
or
<blockquote><pre>
DB2ODBC:database=dbname;DRIVER={IBM DB2 ODBC DRIVER};Hostname=hostipaddr;PROTOCOL=TCPIP;port=db2port;UID=myuserid;PWD=mypw</pre></blockquote>
The following custom parameters can also be used in the following syntax:

<ul>

<li> <b>Tables=schema1.table1(geometry column1),schema2.table2(geometry column2)</b>:
    By using this parameter you can specify the subset of the layers to be used by the driver. If this parameter is not set,
	the layers are retrieved from the DB2GSE.ST_GEOMETRY_COLUMNS metadata view.
	You can omit specifying the schema and the geometry column portions of the syntax. </li>

</ul>
    <p>The parameter names are not case sensitive in the connection strings.</p>
    <p>Specifying the <b>
    Database</b> parameter is required by the driver in order to select the proper database.</p>

<h2>Layers</h2>

<p>By default the DB2 driver will only look for layers that are registered in the <i>DB2GSE.ST_GEOMETRY_COLUMNS</i> metadata table.

<h2>SQL statements</h2>

<p>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 <a href="ogr_sql.html">OGR SQL</a> engine, by passing <strong>"OGRSQL"</strong>
string to the ExecuteSQL() method, as the name of the SQL dialect.</p>

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

<h2>Creation Issues</h2>

<p>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.</P>

<h3>Layer Creation Options</h3>

<ul>

<li> <b>OVERWRITE</b>: This may be "YES" to force an existing layer of the
desired name to be destroyed before creating the requested layer.</li>
<li> <b>LAUNDER</b>: This may be "YES" to force new fields created on this
layer to have their field names "laundered" into a form more compatible with
DB2.  This converts to lower case and converts some special characters
like "-" and "#" to "_".  If "NO" exact names are preserved.
The default value is "YES".  If enabled the table (layer) name will also be laundered.</li>
<li> <b>PRECISION</b>: This may be "YES" to force new fields created on this
layer to try and represent the width and precision information, if available
using numeric(width,precision) or char(width) types.  If "NO" then the types
float, int and varchar will be used instead.  The default is "YES".
<li> <b>DIM={2,3}</b>: Control the dimension of the layer.  Defaults to 2.</li>
<li> <b>GEOM_NAME</b>: Set the name of geometry column in the new table.  If
omitted it defaults to <i>ogr_geometry</i>.</li>
<li> <b>SCHEMA</b>: Set name of schema for new table.
The default schema is that of the userid used to connect to the database</li>
<li> <b>SRID</b>: Set the spatial reference id of the new table explicitly.
The corresponding entry should already be added to the spatial_ref_sys metadata table. If this parameter is not set the SRID is derived from the authority code of source layer SRS.</li>
</ul>

<h3>Spatial Index Creation</h3>

<p>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.
</p>



<h2>Examples</h2>

<p>Creating a layer from an OGR data source</p>
<blockquote><pre>
ogr2ogr -overwrite  DB2ODBC:database=sample;DSN=sampDSN zipcodes.shp</pre></blockquote>

<p>Connecting to a layer and dump the contents</p>
<blockquote><pre>
ogrinfo -al DB2ODBC:database=sample;DSN=sampDSN;tables=zipcodes</pre></blockquote>

</body>
</html>