shp2sde

The shp2sde command converts an ESRI shapefile to an ArcSDE geodatabase feature class. It converts both the attributes and the geometry. 

Note: This function is not supported on 64-bit Windows, Linux, or HP-Itanium.

Usage syntax

shp2sde -o append -l <table,column> [-V <version_name>]
-f <shape_file> [-I] [-a {none | all | file=<file_name>}]
[-r <reject_shpfile>] [-c <commit_interval>] [-v]
[-i {<service> | <port#> | <direct connection>}] [-s <server_name>]
[-D <database_name>] -u <DB_user_name> [-p <DB_user_password>]
 

shp2sde -o create -l <table,column> -f <shape_file> [-I]
[Spatial_Index] [{-R <SRID> | [Spatial_Ref_Opts]}]
[-S <layer_description_str>] [-v] [-L {ON | OFF}]
[-P {HIGH | LOW}] [-e <entity_mask>] [-k <config_keyword>]
[-M <minimum_ID>] [-a {none | all | file=<file_name>}]
[-r <reject_shpfile>] [-V <version_name>]
[-C <row_id_column>[,{SDE | USER},<min_ID>]]
[-c <commit_interval>] [-i {<service> | <port#> | <direct connection>}]
[-s <server_name>] [-D <database_name>] -u <DB_user_name>
[-p <DB_user_password>]
 

shp2sde -o init -l <table,column> -f <shape_file> [-I] [-v]
[-a {none | all | file=<file_name>}] [-r <reject_shpfile>]
[-c <commit_interval>] [-i {<service> | <port#> | <direct connection>}]
[-s <server_name>] [-D <database_name>] -u <DB_user_name>
[-p <DB_user_password>]
 

Where

[Spatial_Ref_Opts] := [-x <xoffset,yoffset,xyscale[,xyClusterTol]>]
[-z <zoffset,zscale[,zClusterTol]>] [-m <moffset,mscale[,mClusterTol]>]
[-G {<projection_ID> | file=<proj_file_name>}]

[Spatial_Index] := [-g [Grid_Options] | GRID,[Grid_Options] | AUTOMATIC | NONE | RTREE ]

[Grid_Options] : = [<grid_sz0>[,<grid_sz1>[,<grid_sz2>]] [,][{FULL | SPARSE}]
 

shp2sde -h

shp2sde -?
 

Conversion table

Shape to ArcSDE entity (feature) type mapping

Shape ArcSDE entity (feature)
point point
multipoint multipart points
arc 1:n lines (spaghetti) or simple lines (line strings)

Note: If the feature class allows both lines and simple line features, all features that pass validation are stored as simple line features, while the rest are stored as lines. If the feature class supports only lines, all features are stored as lines. If the feature class supports only simple line features, all features unable to pass verification are discarded.

polygon 1:n area features
nil nil

 

Operations

Operation Description
append Adds features to an existing feature class (the default)
create Creates a new feature class and imports features from the shapefile into it; returns an error if the feature class already exists
init Deletes all features of an existing feature class before importing new features (not allowed on versioned data)

 

Options

Options Description
-a Attribute modes
none: Does not load any attributes (the default)

The business table of the feature class is populated with the shape records, and the spatial column is populated with a sequential number. This option allows import of data created with the -a none option of the sde2shp command in versions 2.1 or 2.1.1.

all: Loads all attribute columns

If an attribute table doesn't exist for the feature class, one is created. Otherwise, the incoming schema must be union compatible with the table if using the append or init option.

file=<file_name>: A file containing lines specifying how the attributes in the shapefile will be brought into the ArcSDE geodatabase.

The form of the entries in the file is as follows:

<shpCol> [sdeCol] [type] [size] [nDecs] [NOT_NULL]

The shpCol is the column from the shapefile, while the sdeCol is the new name of the column in the ArcSDE geodatabase. The type specifies a legal data type. The size is the maximum size of the column and nDecs the number of digits to the right of the decimal point for floating point data types. NOT NULL, if specified, requires that the column must have a nonNULL value.

Supported types include the following:
INT16
INT32
INT64
FLOAT32
FLOAT64
STRING
NSTRING
DATE

Note: Mapping a numeric column type into string column type and
vice versa is not permitted.

-c Commit rate (default: AUTOCOMMIT value from giomgr.defs)
-C Row ID's column_name, column_type, and minimum_id
-D Database name (not supported on Oracle)
-e Entity types allowed (npsla3+M)

n—Nil
p—Point shapes
s—Line (spaghetti) shapes
l—Simple line (line string) shapes
a—Area shapes
3—Three-dimensional shapes, which can be added to the entity type mask with the -o add operation only
+—Multipart shapes
M—Measures on coordinates. The -m option is required if measures on coordinates is a defined shape type.
-f Path to and name of the shapefile
-g Spatial index type and parameters
 
GRID,<grid_sz1>[,<grid_sz2>[,<grid_sz3>]] ,[FULL|SPARSE] Creates multilevel grid index
(Grid 2 and grid 3 are optional and are not used with Oracle Spatial, Informix, PostgreSQL, or SQL Server spatial types.)

Grid values are only valid for spatial indexes on feature classes stored in Oracle or SQL Server that use binary storage or feature classes stored in Oracle or DB2 that use ST_Geometry storage.

If you don't enter grid values, it is the same as specifying an AUTOMATIC spatial index type.

FULL grids create a spatial index grid on the entire feature envelope. This is the default option if GRID is specified and is the type of grid always created in ArcSDE 9.1 and lower.

SPARSE grids create spatial index grids only where grids actually include parts of the feature.

See the Discussion section for more details.

AUTOMATIC For Oracle Spatial, Informix, and PostgreSQL, this is RTREE.

For all other storage types, if a grid index is required but not specified, the first grid size is calculated and set based on this calculation:

grid level 1 = Maximum Delta / default number of grids
if (grid level 1 * XY scale ) < SE_MIN_GRIDSIZE)
grid level 1 = SE_MIN_GRIDSIZE / XY scale

Where:

Maximum Delta is the result of a comparison between the values for Delta X or Delta Y. Maximum Delta is the larger of the two values.

Delta X is the maximum X of the shapefile extent minus the minimum X of the shapefile extent.

Delta Y is the maximum Y of the shapefile extent minus the minimum Y of the shapefile extent.

The default number of grids is 64.

SE_MIN_GRIDSIZE is 256.

The XY scale is the system_units_range divided by the Maximum Delta. (The result of this calculation is rounded down. For example, if the result is 17399, it is rounded down to 17000; if the result is 2597, it is rounded down to 2500.)

The system_units_range for a high precision layer is 9007199254740990 * 0.6, and the system_units_range for a low precision layer is 2147483645.

Note: Only the first grid level is calculated; the second and third grids are set to 0.

NONE No spatial index is created.
RTREE Creates an R-tree index
-G Coordinate system specifier

<projection_id>coordinate system ID (For the integer codes, see the pedef.h file installed with the ArcSDE C API or the Coordinate system IDs topic found here: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/ref_coordsystems.htm.)

file=<proj_file_name>file containing coordinate system description string

-h or -? Use either of these options to see the usage and options for the command. Note: If using a C shell, use -h or "-\?".
-i ArcSDE service name, port number, or direct connection information (default: esri_sde or 5151)
-I Disable buffered inserts (default: ON).
-k Configuration keyword present in DBTUNE table (default: DEFAULTS); used with the create operation only.
-l Feature class and spatial column to load

They must exist, and the user must either own the table or have INSERT access to it. If you do not own the table, qualify the table name as owner.table.

-L Enables or disables autolocking

Set to ON, autolocking is enabled; set to OFF, autolocking is disabled. When autolocking is enabled, the session attempts to lock the area defined by a feature envelope before the feature can be edited. If the area is already locked, an error is returned. (default: ON)

-m Measure offset, scale, and cluster tolerance separated by commas

If the -m is not specified, the measure offset is calculated from the shapefile's minimum measure value, the measure scale is calculated from the shapefile's measure delta, and the measure cluster tolerance is calculated based on the spatial reference system. If these values cannot be obtained, the measure offset and scale is set to 0.0, 1.0, and the cluster tolerance is set to 2 times the cell resolution.

-M Minimum ID

New shape IDs are assigned the larger of the minimum ID or the maximum assigned ID + one (default: 1).

-o Operation
-p DBMS user password
-P The internal storage of the feature geometry, either BASIC (32 bit) or HIGH (64 bit) (default: HIGH)

BASIC precision is not supported for geodatabases in PostgreSQL.

-r Rejects shapefile name for rejected shapes

Shapes are only written to the rejects file if they can be. If the originating shapefile was not created according to the ESRI shapefile specification, it may not be possible to write a rejected shape record to the rejects shapefile. For instance, if the shapefile contains a numeric field that exceeds a width of 19, the rejects shapefile cannot be created.

-R Spatial reference ID (SRID)
-s ArcSDE server host name (default: localhost)
-S Feature class description string
-u DBMS user name
-v Verbose optionreports records committed at the commit interval
-V Geodatabase version name
-x The x-offset, y-offset, x,y scale values, and x,y cluster tolerance separated by commas

If the -x option is not specified, the x- and y-offset is calculated from the minimum x- and y-coordinate values of the shapefile, the x,y scale is calculated from the maximum x or y delta value, and the x,y cluster tolerance is calculated based on the spatial reference system. If the x and y delta values cannot be obtained from the shapefile, the default is 0.0, 0.0, 1000. If no spatial reference system is specified, the cluster tolerance is calculated as and 2 times the cell resolution.

-z The z-offset, scale values, and cluster tolerance separated by commas

If the -z option is not specified, the z-offset is calculated as the shapefile's minimum z-value, the z-scale is calculated from the shapefile's z delta, and the z-cluster tolerance is calculated based on the spatial reference system. If the values cannot be obtained from the shapefile, the default is 0.0, 1.0, and 2 times the cell resolution.

 

ArcSDE support for database file types

Type Width Description Storage
B 10 Binary field No
C 1–254 Character Yes
D 8 Date field specified as eight ASCII characters in YYYYMMDD format Yes
F 1–20 Numeric floating point field See below
G 10 General field No
L 1 Logical field Yes
M 10 Memo field No
N 1–19 Numeric fixed position field Yes
P 10 Picture field No
V 10 Variable field No
The dBASE F-type column is not created in the geodatabase, but the geodatabase writes to an existing F-type column. Therefore, the sde2shp init operation does not create an F-type column, but the sde2shp append operation writes to a shapefile containing an existing F-type. The shp2sde command reads an F-type column.

 

Discussion

The shp2sde command converts shapefiles to ArcSDE geodatabase feature classes.

The shp2sde command can convert up to 15 digits of precision or the maximum precision imposed by the SE_DOUBLE data type.

The shp2sde command reports the status of the shapefile to feature class transfer in the form of features converted and features stored. The meaning of these statistics is as follows:

The two values can differ if the shapes within a multipart shapefile are separated and stored as several features. This occurs if the feature class entity type does not allow multipart features. To allow multipart features to be stored in the feature class, change the feature class entity type with either the sdelayer command or by adjusting the properties of the feature class with the ArcCatalog application.

Note: The metadata for a feature class in an ArcSDE geodatabase is stored in the table GDB_USERMETADATA. Only applications written with ArcObjectssuch as ArcCatalogcan write to the geodatabase (GDB) tables, including the GDB_USERMETADATA table. The shp2sde command is not an ArcObjects application, is not geodatabase aware, and, therefore, does not write the metadata contained in the XML file associated with the shapefile to the geodatabase.

Row IDs/Object IDs

The row ID (also known as an object ID) column of a business table must be a unique integer column. The row ID column is always required if the feature class is stored in a DB2, Informix, or PostgreSQL or Oracle DBMS using the ST_Geometry spatial type, or if the feature class contains an Oracle Spatial SDO_GEOMETRY column. Feature classes stored in the SQL Server DBMS and the Oracle DBMS (except those that have an SDO_GEOMETRY column or ST_Geometry column) are not required to have a row ID defined unless they are registered with the geodatabase or they are to be registered as multiversioned.

For those feature classes required to have a row ID defined, by default, shp2sde creates a unique integer column, objectid, maintained by ArcSDE, and with an initial value set to 1. The -C option allows you to control the name, type, and initial value of the row ID column.

If the -C option is specified, the column name can be any name that follows the DBMS naming convention. The name defaults to objectid. The type can be either maintained by ArcSDE (ArcSDE controls the sequence of values entered into the column, which ArcGIS requires of any table registered with the geodatabase), or user maintained (your application controls the sequence of values entered into the row ID.) The type defaults to having ArcSDE maintain the row ID. The initial value of the row ID can be a positive integer. The initial value defaults to 1.

In ArcSDE 9.1 or prior, if you did not use the -C option to specify a column to use for the row ID, shp2sde would search for an existing column named objectid and use that for the row ID. If such a column didn't exist, it would create one. Beginning with ArcGIS Server 9.2, shp2sde does not search for and use an existing column named objectid. If a column named objectid already exists in the shapefile, shp2sde adds a column named objectid1 to use as the row ID. Therefore, if your shapefile contains a unique integer column named objectid that you want to use for the row ID, you must use the -C option to specify it as your row ID.

The following is an example of a row ID column being created with the -C option. The row ID column is wid; it is maintained by ArcSDE, and its initial value is set to 1. If the -C option is not specified in a situation in which the row ID column is required, the row ID column is objectid, is maintained by ArcSDE, and its initial value is set to 1.

shp2sde -o create -l borders,feature -f world -C wid,SDE,1 -e -u world

In this example, an existing objectid column is specified with the -C option.

shp2sde -o create -l studyareas,feature -f c:\data\sites -C objectid,SDE,1 -e -u prof

Spatial indexes

You have the option to create sparse spatial index grids. Sparse grids populate the spatial index with information for only those grids that actually contain a portion of a feature. For example, if you create a spatial index on a river feature class, only those grids that the river crosses are indexed for the river.

This could be more efficient for spatial queries, because grids that do not qualify as crossing the feature (in this case, rivers) are eliminated from the query results during the primary filter process ArcSDE performs when executing spatial queries. Be aware that if you use third-party applications to perform envelope-on-envelope spatial queries, using a sparse index grid affects query results.

If instead you used a full grid for the rivers, the nonqualifying grids are still eliminated, but they are not eliminated until the secondary filter process.

When you create a feature class from a shapefile, if the feature class is in normal I/O mode and there are 0 features, no spatial index is created unless you specify index information. If there are features present, the spatial index is created with the offsets you specify with the -x option. ESRI recommends you specify the -g and -x information that will work best with your data. However, if you do not specify the index type, the AUTOMATIC type for the index is used. See the -g option description for details on the AUTOMATIC type.

If the feature class is in load_only I/O mode, the spatial index is created when the feature class is returned to normal I/O mode.

String data types

The shp2sde command automatically brings character fields into the geodatabase as strings. If the fields are actually NSTRING, you need to create a file that contains entries specifying the definition of the attribute columns in the geodatabase. In this file, you specify which columns should be stored in the geodatabase as NSTRING. The definition file you create is specified with the -a option in the shp2sde -o create command. See the example for "Creating a new feature class and importing features from a shapefile" for specific instructions on using this functionality.

Code pages

Character encoding for string data is indicated by the code page. Shapefiles have a dBase header file (.dbf) that can store the code page for the shapefile. If the shapefile was created using ESRI software, the code page will be set in the .dbf, and you should be able to import it to your ArcSDE geodatabase without the characters getting messed up. If the shapefile was created by a third-party product or you do not know how the shapefile was created, you might want to check if a code page is set.

To see if the code page is set in the .dbf header, open the .dbf at a DOS prompt in debug mode. To do this, change directories to where the .dbf you want to open resides. Type the following, substituting the name of your .dbf for <file_name>:

debug <file_name>.dbf

When the dash appears on the next line, type d and hit return. Whether or not the code page is set is indicated at the 30th byte. If the 30th byte is 00, the code page is not set. If it is anything other than 00, the code page is set.

To find the 30th byte, you count the sets of characters in the center. In this example, you start with 03, which counts as 1. Count over 30, counting only the character sets shown in blue in this example. If the set is 00, the code page is not set. The 30th character in this example is 0E. Therefore, the code page is set.

0B8D:0100 03 64 02 07 01 00 00 00-A1 00 41 00 00 00 00 00 .d........A.....
1489:0110 00 00 00 00 00 00 00 00-00 00 00 00 00 0E 00 00 ................

If the code page is not set in the .dbf header, you can create a code page file (.cpg) to store the code page. To create a code page file, you use a text editor, such as vi or Notepad, add the code page identifier for the shapefile to the file, and save it with a .cpg extension in the same location as the other files that make up the shapefile. You have to be sure you know the encoding used for the shapefile so you place the correct code page in the .cpg file.

If for some reason you have a .cpg file and the code page is set in the .dbf, the information in the .dbf header takes priority when importing a shapefile. If no code page is set in the .dbf, the code page is read from the .cpg file. If the code page is not set in the .dbf and no .cpg file is present, the code page of the current locale of the operating system from which shp2sde is being run (the server where ArcSDE is installed) will be used.

The following is a list of supported code pages for shapefiles.

Code page type Identifier Language
OEM 437 Latin U.S.
OEM 708 Arabic
OEM 720 Arabic
OEM 737 Greek
OEM 775 Baltic
OEM 850 Western European
OEM 852 Central European
OEM 855 Cyrillic
OEM 857 Turkish
OEM 860 Portuguese
OEM 861 Icelandic
OEM 862 Hebrew
OEM 863 French Canadian
OEM 864 Arabic
OEM 865 Nordic
OEM 866 Cyrillic
OEM 869 Greek
OEM 932 Japanese
OEM 936 Simplified Chinese
OEM 950 Traditional Chinese
ANSI 1250 Eastern European Latin
ANSI 1251 Cyrillic
ANSI 1252 Western European Latin
ANSI 1253 Greek
ANSI 1254 Turkish
ANSI 1255 Hebrew
ANSI 1256 Arabic
ANSI 1257 Baltic
ANSI 1258 Vietnamese
ANSI Big5 Traditional Chinese
ANSI SJIS Shift-JIS, Japanese
ISO 88591 Latin alphabet no. 1 (Danish, Dutch, English, Faeroes, Finish, French, German, Icelandic, Irish, Italian, Norwegian, Portuguese, Spanish, and Swedish)
ISO 88592 Latin alphabet no. 2 (Albanian, Czech, English, German, Hungarian, Polish, Rumanian, Serbo-Croatian, Slovak, and Slovene)
ISO 88593 Latin alphabet no. 3 (Afrikaans, Catalan, Dutch, English, Esperanto, German, Italian, Maltese, Spanish, and Turkish)
ISO 88594 Latin alphabet no. 4 (Danish, English, Estonian, Finnish, German, Greenlandic, Lappish, Latvian, Lithuanian, Norwegian, and Swedish)
ISO 88595 Latin Cyrillic alphabet (Bulgarian, Byelorussian, English, Macedonian, Russian, Serbo-Croatian, and Ukrainian)
ISO 88596 Latin/Arabic alphabet (English and Arabic)
ISO 88597 Latin/Greek alphabet (English and Greek)
ISO 88598 Latin/Hebrew alphabet (English and Hebrew)
ISO 88599 Latin alphabet no. 5 (Western European and Turkish)
ISO 885910 Latin alphabet no. 6 (Danish, English, Estonian, Faeroes, Finnish, German, Greenlandic, Lappish, Latvian, Lithuanian, Norwegian, and Swedish)
ISO 885913 Baltic languages
ISO 885915 Latin alphabet no. 9 (Danish, German, English (GB), Spanish, Finnish, French Canadian, French, Icelandic, Italian, Dutch, Norwegian, Portuguese, and Swedish)
ISO EUC Includes EUC-JP (Japanese), EUC-KR (Korean), EUC-TW (Taiwanese), and EUC-CN (Chinese)
Unicode UTF-8 8-bit Unicode transformation format

Note that if you have a UTF-8 code page in the shapefile and, therefore, have NSTRING data in the attributes table, you will need to use the file described in the last section to map the NSTRING fields in the shapefile to NSTRING fields in the feature class when importing data.

Examples

Appending features to a feature class

The append operation adds features to an existing feature class. In the following example, the features from the shapefile vireo are appended to the nests table. The -a option specifies that none of the attributes from the vireo shapefile are to be brought into the nests' business table; only the spatial information is to be populated. This might be useful if you plan to collect more up-to-date field data about the vireos after adding the spatial information to the nests feature class.

shp2sde -o append -l nests,shape -f vireo -a none -u av -v

By specifying the -v option, a report of the records is committed at the commit interval. Since -c isn't specified, the commit rate defaults to the AUTOCOMMIT value in the SERVER_CONFIG table (SDE_server_config table in SQL Server and PostgreSQL databases).

Creating a new feature class and importing features from a shapefile

The create operation creates a feature class and imports features from the specified shapefile. If the feature class you are trying to create already exists in the geodatabase, an error is returned.

This example creates a feature class, blocks, and imports features from the shapefile census_data in geographic coordinates:

shp2sde -o create -l blocks,shape -f census_data -a all -x -200,-100,100000 -g GRID,1000,SPARSE -G 4269 -e a -k block_attr -u av

This example converts the world shapefile to the feature class borders. The data is small scale, so the scale (in the -x option) is set to 10,000. The example also uses the -r option to write any rejected shapes to a new shapefile, rejects.

shp2sde -o create -l borders,feature -f world -g AUTOMATIC -x -180,-90,10000 -e a -k WORLD -a all -r rejects -s stout -u world

When creating the feature class from the shapefile, you can specify to create character columns as an NSTRING data type if your geodatabase is set up to store Unicode strings. You store strings as NSTRING using the -a option to indicate a file, which contains entries specifying the definition of the attribute columns in the geodatabase. For example, a shapefile, counties, has the following definition:

Column name Type Width Decimal Places
AREA N 15 3
NAME C 40 -
FIPS_CODE C 2 -
FID N 10 -
SHAPE Geometry 0 -

To convert this to a feature class in an ArcSDE geodatabase set to store Unicode data, a file can be created to define the columns. In the file, the entries should be in the following format:

<shpCol> [sdeCol] [type] [size] [nDecs] [NOT_NULL]

The shpCol is the column name in the shapefile, the sdeCol is the new name of the column in the ArcSDE geodatabase. The type specifies a legal data type. The size is the maximum size of the column and nDecs the number of digits to the right of the decimal point for floating point data types. NOT NULL, if specified, requires that the column must have a nonNULL value.

As indicated by the brackets, all but the first parameter is optional. If you do not supply values for the other parameters, default values are used. In the case of type, if the data type was character in the shapefile, the default in the feature class will be STRING. Therefore, to create an NSTRING column, you must specify the type.

If you do not specify the NOT_NULL parameter, the column in the feature class will allow null values. If you do not specify sdeCol, size, or nDecs, they will be the same as they were in the shapefile.

For the counties shapefile, the following entries could be placed in a file, county_def:

AREA COUNTY_AREA

NAME NAME NSTRING 45 0

FIPS_CODE FIPS

FID OBJECTID INT32 10 0 NOT_NULL

The file specifies different names for the AREA, FIPS_CODE, and FID columns, and disallows null values in the OBJECTID column.  It also indicates that the NAME column will have a greater maximum length (45 instead of 40) in the feature class and that data in the NAME column will be stored as NSTRING.

Next, shp2sde -o create is used to convert the shapefile to a feature class in the ArcSDE geodatabase.

shp2sde -o create -l counties,shape -f e:\data\counties.shp -a file=e:\data\county_def.txt -v -i 5000 -u tech

Shape to Layer Loading Administration Utility

Change NAME col_def from SE_STRING,40,0 to SE_NSTRING
Set X_offset = -180
Set Y_offset = -90
Set XY_scale = 5000000
Set Grid Size0 = 6

50 records processed
100 records processed
150 records processed
165 records processed
Setting layer to NORMAL-IO mode
165 features converted.
165 features stored.

You will note that the shape column was not defined in the county_def file. That is because the -a option dictates the attribute columns brought in from the shapefile; the geometry column is automatically brought into the feature class. To specify a geometry storage other than the default for the geodatabase, you would use the -k option.

Deleting features from an existing feature class before importing new features

The init operation deletes all features of an existing feature class before importing new features. This operation cannot be done on versioned data.

shp2sde -o init -l stations,feature -f trains -a all -u av

In the previous example, the -a option is specifying that all attribute columns be imported to the stations feature class. Remember, the incoming schema of the trains shapefile must be union compatible with the stations' attribute table for this to work.

 

Home

Copyright © Environmental Systems Research Institute, Inc. 2004 - 2010.