import_shape

Use the import_shape command to import a shape file to a database that is enabled for spatial operations.

This command can operate in either of two ways, based on the -createTableFlag parameter:
  • IBM® Spatial Support for Db2 for z/OS® can create a table that has a spatial column and attribute columns, and it can then load the table's columns with the file's data.
  • Otherwise, the shape and attribute data can be loaded into an existing table that has a spatial column and attribute columns that match the file's data.
Important: Using a message file is optional; however, consider specifying a message file so that any errors and informational messages are written to the message file. The import process continues even if an error occurs on a row. If many errors occur, the import process will be much slower.

The input files must reside on the HFS file under the z/OS UNIX environment, so the binder and the user must have read access to the given directory. Also, the message file will be generated on a valid HFS directory under the z/OS UNIX environment if specified. Therefore, the binder and the user must have write access to the given directory.

IBM Spatial Support for Db2 for z/OS does not support the -inlineLength parameter and the -exceptionFile parameter for this command. If you specify either of these parameters, the parameter will be ignored.

Authorization

The user ID must have the necessary privileges for reading the input files and optionally writing error files. Additional authorization requirements vary based on whether you are importing into an existing table or into a new table.
  • When importing shape data to an existing table, your user ID must hold one of the following authorities and privileges:
    • SYSADM or DBADM authority on the database that contains the table or view
    • INSERT and SELECT privilege on the table or view
  • When creating a table automatically and importing shape data to the new table, your user ID under must hold the authorizations that are needed for the CREATE TABLE statement.

Command syntax

DSN5SCLP /import_shape DALLAS
	-fileName file_name
	[-inputAttrColumns input_columns]
	-srsName srs_name
	[-tableSchema table_schema]
	-tableName table_name
	[-tableAttrColumns attr_columns]
	[-createTableFlag create_flag]
	[-tableCreationParameters tc_params]
	-spatialColumn spatial_column
	[-typeSchema type_schema]
	[-typeName type_name]
	[-inlineLength length]
	[-idColumn id_column]
	[-idColumnIsIdentity id_flag]
	[-restartCount rs_count]
	[-commitScope commit_count]
	[-exceptionFile efile_name]
	[-messagesFile mfile_name]
	[-client client_flag]

Parameter descriptions

All parameters are required and case-sensitive unless otherwise indicated.

-fileName
Specifies the full path name of the shape file that is to be imported. You must specify a non-empty value for this parameter.

If you specify the optional file extension, specify either .shp or .SHP. IBM Spatial Support for Db2 for z/OS first looks for an exact match of the specified file name. If IBM Spatial Support for Db2 for z/OS does not find an exact match, it looks first for a file with the .shp extension, and then for a file with the .SHP extension.

See Usage notes for a list of required files, which must reside on the HFS file under the z/OS UNIX environment.

-inputAttrColumns
Specifies a list of attribute columns to import from the dBASE file. This parameter is optional.

If this parameter is not specified, all columns are imported. If the dBASE file does not exist, this parameter must not be specified.

To specify a non-empty value for this parameter, use one of the following specifications:
  • List the attribute column names. The following example shows how to specify a list of the names of the attribute columns that are to be imported from the dBASE file:
    
    N(COLUMN1,COLUMN5,COLUMN3,COLUMN7)
    
    If a column name is not enclosed in double quotation marks, it is converted to uppercase. Each name in the list must be separated by a comma. The resulting names must exactly match the column names in the dBASE file.
  • List the attribute column numbers. The following example shows how to specify a list of the numbers of the attribute columns that are to be imported from the dBASE file:
    
    P(1,5,3,7)
    
    Columns are numbered beginning with 1. Each number in the list must be separated by a comma.
  • Indicate that no attribute data is to be imported. Specify "", which is an empty string that explicitly specifies that IBM Spatial Support for Db2 for z/OS is to import no attribute data.

This parameter is not case-sensitive.

-srsName
Identifies the spatial reference system that is to be used for the geometries that are imported into the spatial column. You must specify a non-empty value for this parameter.

The spatial column will not be registered. The spatial reference system (SRS) must exist before the data is imported. The import process does not implicitly create the SRS, but it does compare the coordinate system of the SRS with the coordinate system that is specified in the .prj file (if available with the shape file). The import process also verifies that the extents of the data in the shape file can be represented in the given spatial reference system. That is, the import process verifies that the extents lie within the minimum and maximum possible X, Y, Z, and M coordinates of the SRS.

-tableSchema
Identifies the schema to which the table that is specified in the -tableName parameter belongs. This parameter is optional.

If this parameter is not specified, the value in the CURRENT SCHEMA special register is used as the schema name for the table.

-tableName
Identifies the unqualified name of the table into which the imported shape file is to be loaded. You must specify a non-empty value for this parameter.

-tableAttrColumns
Specifies the table column names where attribute data from the dBASE file is to be stored. This parameter is optional.

If this parameter is not specified, the names of the columns in the dBASE file are used.

If this parameter is specified, the number of names must match the number of columns that are imported from the dBASE file. If the table exists, the column definitions must match the incoming data. See Usage notes for an explanation of how attribute data types are mapped to Db2 data types.

This parameter is not case-sensitive.

-createTableFlag
Specifies whether the import process is to create a new table. This parameter is optional.

If this parameter is not specified, or is any value other than 0 (zero), a new table is created. (If the table already exists, an error is returned.) If this parameter is 0 (zero), no table is created, and the table must already exist.

If you want to create a target table in a separate table space, first create the table, and then create the LOB table space, auxiliary table, and index for the target table before using the import shape operation.

After creating the required LOB table space, auxiliary table, and index for the target table, specify 0 (zero) for the -createTableFlag option to import shape data and attributes data to the table. The import shape operation does not create a LOB table space, an auxiliary table, or an index for the LOB column.

-tableCreationParameters
Specifies any options that are to be added to the CREATE TABLE statement that creates a table into which data is to be imported. This parameter is optional.

If this parameter is not specified, no options are added to the CREATE TABLE statement.

To specify any CREATE TABLE options, use the syntax of the Db2 CREATE TABLE statement. For example, to specify a database and Unicode option for character columns, specify:
IN dbName CCSID UNICODE

This parameter is not case-sensitive.

-spatialColumn
Identifies the spatial column in the table into which the shape data is to be loaded. You must specify a non-empty value for this parameter.

For a new table, this parameter specifies the name of the new spatial column that is to be created. Otherwise, this parameter specifies the name of an existing spatial column in the table.

-typeSchema
Specifies the schema name of the spatial data type (specified by the -typeName parameter) that is to be used when creating a spatial column in a new table. This parameter is optional.

If this parameter is not specified, a value of DB2GSE is used.

-typeName
Identifies the data type that is to be used for the spatial values. This parameter is optional. The valid data types are ST_Point, ST_MultiPoint, ST_MultiLineString, ST_MultiPolygon, or ST_Geometry.
If this parameter is not specified, the data type is determined by the shape file and is one of the following types:
  • ST_Point
  • ST_MultiPoint
  • ST_MultiLineString
  • ST_MultiPolygon
Note that shape files, by definition, allow a distinction between only points and multipoints, but not between polygons and multipolygons or between linestrings and multilinestrings.

If you are importing into a table that does not yet exist, this data type is also used for the data type of the spatial column.

This parameter is not case-sensitive.

-inlineLength
This parameter is not supported and always will be null. If you specify this parameter, the parameter is ignored.

-idColumn
Identifies a column that is to be created to contain a unique number for each row of data. The unique values for that column are generated automatically during the import process. This parameter is optional.

If this parameter is not specified, no column is created or populated with unique numbers.

Restriction: You cannot specify an -idColumn name that matches the name of any column in the dBASE file.

The requirements and effect of this parameter depend on whether the table already exists.
  • For an existing table, the data type of the -idColumn parameter can be any integer type (INTEGER, SMALLINT, or BIGINT).
  • For a new table that is to be created, the column is added to the table when the stored procedure creates it. The column will be defined as follows:
    
    INTEGER NOT NULL PRIMARY KEY 
    
    If the value of the -idColumnIsIdentity parameter is not null and not 0 (zero), the definition is expanded as follows:
    
    INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY 
    ( START WITH 1 INCREMENT BY 1 )
    
-idColumnIsIdentity
Indicates whether the specified id_column is to be created using the IDENTITY clause. This parameter is optional.

If this parameter is 0 (zero) or not specified, the column is not created as the identity column. If the parameter is any value other than 0, the column is created as the identity column. This parameter is ignored for tables that already exist.

-restartCount
Specifies that an import operation is to be started at record n + 1. The first n records are skipped. This parameter is optional.

If this parameter is not specified, all records (starting with record number 1) are imported.

-commitScope
Specifies that a COMMIT is to be performed after at least n records are imported. This parameter is optional.

If this parameter is not specified, a value of 0 (zero) is used, and no records are committed.

-exceptionFile
This parameter is not supported and always will be null. If you specify this parameter, the parameter is ignored.

-messagesFile
Specifies the full path name of the file (HFS file under the z/OS UNIX environment) that is to contain messages about the import operation. This parameter is optional.

If the parameter is not specified, no file for IBM Spatial Support for Db2 for z/OS messages is created.

The messages that are written to the messages file can be:
  • Informational messages, such as a summary of the import operation
  • Error messages for data that could not be imported, for example because of different coordinate systems

The user who runs the job that calls the command must have the necessary privileges on the server to create the file. If the file already exists, the file will be overwritten.

Usage notes

The import_shape command uses from one to four files:
  • The main shape file (.shp extension). This file is required.
  • The shape index file (.shx extension). This file is optional.
  • A dBASE file that contains attribute data (.dbf extension). This file is required only if attribute data is to be imported.
  • The projection file that specifies the coordinate system of the shape data (.prj extension). This file is optional. If this file is present, the coordinate system that is defined in it is compared with the coordinate system of the spatial reference system that is specified by the -srsId parameter.
The following table describes how dBASE attribute data types are mapped to Db2 data types. All other attribute data types are not supported.
Table 1. Relationship between Db2 data types and dBASE attribute data types
.dbf type .dbf length␢ (See note) .dbf decimals␢ (See note) SQL type Comments
N < 5 0 SMALLINT  
N < 10 0 INTEGER  
N < 20 0 BIGINT  
N len dec DECIMAL(len,dec) len<32
F len dec REAL len + dec < 7
F len dec DOUBLE  
C len   CHAR(len)  
L     CHAR(1)  
D     DATE  
Note: This table includes the following variables, both of which are defined in the header of the dBASE file:
  • len, which represents the total length of the column in the dBASE file. IBM Spatial Support for Db2 for z/OS uses this value for two purposes:
    • To define the precision for the SQL data type DECIMAL or the length for the SQL data type CHAR
    • To determine which of the integer or floating-point types is to be used
  • dec, which represents the maximum number of digits to the right of the decimal point of the column in the dBASE file. IBM Spatial Support for Db2 for z/OS uses this value to define the scale for the SQL data type DECIMAL.

For example, assume that the dBASE file contains a column of data whose length (len) is defined as 20. Assume that the number of digits to the right of the decimal point (dec) is defined as 5. When IBM Spatial Support for Db2 for z/OS imports data from that column, it uses the values of len and dec to derive the following SQL data type: DECIMAL(20,5).

Example

This example shows how you can use the import_shape command to import a shape file.
DSN5SCLP /import_shape DALLAS +
-fileName /tmp/shapes/zipcode.shp +
-createTableFlag 1 +
-inputAttrColumns "N (AREA, ZIPCODE)" +
-srsName SANDIEGO +
-tableSchema NEWTON -tableName TABLE11 +
-tableCreationParameters "IN DATABASE TMP" +
-typeSchema DB2GSE -typeName ST_MULTIPOLYGON +
-spatialColumn "loc" +
-messagesFile /tmp/shapes/ut07_msg