OpenCities Map CONNECT Edition Help

DGN2DB.EXE Command Line Application

DGN2DB is a geospatial program to load CAD data into a geospatial database. The application has its origins in the DGN2SDO for Oracle tools that were used in the Map V8i and earlier products. DGN2DB is the new 64-bit CONNECT Edition of those tools for Map Advanced and all Map Ultimate editions, and is used to create scripts to load spatial features and tables from MicroStation DGN File elements to a spatial database. DGN2DB extends the use of DGN2SDO by supporting additional spatial database types; Oracle and PostgreSQL/PostGIS in the initial release.

The tools are typically used by database administrators to load MicroStation design file geometries and attributes into a spatial database. The processes are written and executed from the Windows command line, using Windows options like Notepad and the Command Prompt. If you used the DGN2SDO process in the V8i products, you will remember the diagram showing the data flow supported by the DGN2SDO for Oracle application:

The DGN2DB process scans the DGN Files and creates intermediate files, sql scripts, and associated files which are used to create the spatial database features and tables. PL/SQL continues to be the database loader for Oracle.

The following options are from the dgn2db.exe command line help. Use dgn2db.exe -h, -?, or -help to print the help file list.

  Usage: DGN2DB parameter=value (repeat, separating each parameter=value pair with a space)
         (Note: parameter values containing spaces must be surrounded by quotation characters, e.g.,
    IN_LEVEL="Level 2").

Required Parameters:

IN_TYPE=<DGN|XFM>                : Specifies the Mode, or type of files to convert.
IN_FILE=<filename-list>          : Input files to convert (multiple files delimited by |, wildcard
						support.) Not required if using optional OUT_SCHEMA_ONLY=TRUE
						option.
IN_METADB=user/password@service  : Specifies an Oracle database connection from where DGN2DB will
						obtain Oracle Spatial metadata (e.g., valid target coordinate
						systems.)
IN_METADB=host address;port number;database name;username;password  : Specifies a PostGIS database
						connection from where DGN2DB will obtain the PostGIS metadata.
OUT_STORAGE=<ORACLE|POSTGIS>     : Specifies the target database type

Required Parameters for IN_TYPE=DGN:

Required parameters for IN_TYPE=DGN:
IN_GEOM_TYPE=<geometry-type> 	: Specifies a geometry type filter to use in the conversion. Valid
						geometry types are POINT, TEXT, LINE, POLYGON.
OUT_GEOM_TABLE=<out table name> 	: Oracle table name to be used in the table creation and loading
						scripts.

Optional Parameters for IN_TYPE=DGN:
IN_COLOR=<element color number>  : Specifies an element color number to use as a filter in the conversion.
IN_WEIGHT=<element weight>       : Specifies an element weight to use as a filter in the conversion.
IN_STYLE=<element style>         : Specifies an element style to use as a filter in the conversion.
IN_LEVEL=<level-list>            : Select elements on specified levels only.
IN_DB=<database type>,<login string>[,tablename]
                                 : Specify a DB connection to a MSLINK database for processing
					Entity/MSLINK linkages on elements.
IN_QUERY=<where clause of a SQL query> : Filter elements based upon the where clause (requires IN_DB).

Required Parameters for IN_TYPE=XFM:
IN_WK=<workspace name>           : Required. This will cause a specific Bentley Map workspace to be used.
IN_WW=<workset name>             : Required. This will cause a specific Bentley Map workset to be used.
IN_FEATURE=<feature-list>        : Select the features to be converted (multiple features delimited by |,
					wildcard support.)



Optional Parameters for IN_TYPE=XFM:
IN_DB=<database type>,<login string> : Specify a DB connection to a legacy GeoGraphics database for
						processing GeoGraphics features as XFM features.
IN_QUERY=<where clause of a SQL query> : Filter features based upon the where clause (requires IN_DB).
OUT_WM_VALID=<validfrom property>,<validtill property> : The date/time property names to use to create the
								value of a new WM_VALID column.

Required Parameters for OUT_STORAGE=POSTGIS
PSQL_DIR=<path to folder>: PSQL_DIR must contain the path to the folder where the PostgreSQL executable (psql.exe) can be found.
Other Optional Parameters that Apply to All Modes:
IN_EXTENT=<xmin,ymin,xmax,ymax>  : Specifies a spatial extent, used when scanning the input design file. 
					This is only for use with Oracle.
OUT_DIR=<outdir>                 : Overrides the default output directory where SQL Loader scripts are
					placed.
OUT_GEOM_COL=<geometry col name> : Geometry column name to use for generated geometry columns.
                                   Defaults to "OGC_GEOMETRY".
OUT_CS=<output SRID>             : Output coordinate system (Oracle SRID or PostGIS SRID) for the
					generated spatial layers.  Defaults to null.
OUT_GEOM_TOL=<geomtolerance>     : The tolerance to set on generated geometry columns.  Oracle-only.
					Defaults to 0.000000050.
OUT_SPATIAL_INDEX=<TRUE|FALSE>   : A flag indicating whether the generated SQL script for creating spatial
					tables should also contain a SQL statement to create a spatial index
					for the table. Default is TRUE for Oracle.
OUT_INDEX_TYPE=<spatialindextype> : For Oracle only: An override to the spatial index type. Only used if
					OUT_SPATIAL_INDEX is set to TRUE. If this argument is not specified,
					the index type is determined automatically from the input data stream.
OUT_DIM=<2D|3D>                  : Specify the dimension of the generated spatial layer. Default = 2D.
OUT_XDIM=(min_x,max_x)           : Override the generated spatial layer limits for the X axis. Oracle-only
OUT_YDIM=(min_y,max_y)           : Override the generated spatial layer limits for the Y axis. Oracle-only
OUT_ZDIM=(min_z,max_z)           : Override the generated spatial layer limits for the Z axis. Oracle-only
OUT_PK_COL_NAME=<Primary Key name> : Override the generated name for the primary key column.
OUT_PK_START=<start value>       : Override the default starting value for generated Primary Key values.
OUT_DELIM=<char>                 : For Oracle only: Override the field delimiter to use in generated
					SQL*Loader .DAT files.
OUT_SCHEMA_ONLY=<true|false>     : Specifies that table creation and indexing scripts be created, but do
					not generate any SQL*Loader scripts.
OUT_SCHEMA_FEATURES=<true|false> : Specifies that table creation and indexing scripts be created for all
					schema features regardless of whether instances exist in the
					input file(s).

NOTES:

  • All files must have read/write permissions, read-only files are not accepted. This includes files that may be open in MicroStation or OpenCities Map, close them prior to running DGN2DB.
  • PostGIS only supports circular arcs.
  • DGN2DB does not generate topology. The prior DGN2SDO parameters linked to topology are no longer available.

DGN2DB Application Examples

There are two modes to run DGN2DB application in: DGN, and XFM. DGN mode is the simpler of the two and uses the MicroStation Level and Geometry type for input, while XFM mode uses either a current XFM Schema, or a legacy MicroStation GeoGraphics project/workspace and XFM Schema that defines the input. These two examples show a typical DGN2DB process:

Example 1: Running DGN2DB in DGN Mode

Use Windows File Explorer, Notepad, and the Windows Command Prompt for these processes. Browse to your project folder using File Explorer and initialize the Command Prompt from the Start Menu, or by keying in “CMD” from the Windows Search field.

  1. Review the DGN File using OpenCities Map and identify the data geometry type and level to convert. Remember that the valid geometries for IN_TYPE are: Point, Text, Line, Polygon.
  2. Use Notepad to create a batch file with the extension .bat, and for each level/geometry type/other criteria combination add one call to DGN2DB as shown below:
    DGN2DB.bat
    set dgn2db="C:\Program Files\Bentley\Map CONNECT Edition\MapAdvanced\Dgn2Db.exe"
    set myoutdir=D:\data\OutputDGN2DB\myOutputDir
    set inmetadb= myuser/mypassword@myservice
    rem ---------------------------------------
    ECHO All features of the dgn
    % dgn2db % IN_FILE="D:\data\myProject\*.dgn" IN_TYPE=DGN IN_GEOM_TYPE=LINE OUT_GEOM_TABLE=BS_BK OUT_DIR=%myoutdir% IN_METADB=%inmetadb% OUT_STORAGE=ORACLE
    
  3. Run the batch file to create a set of SQL, CTL, DAT and one masterload.bat file (double-click on it, or select it and press enter).
  4. Create a new tablespace in Oracle or PostGIS that will host the new data.
  5. Run the masterload.bat file (use Run as administrator if-necessary). This will create Oracle tables, set the Oracle spatial metadata, and load the geometry into the newly created tables.
masterload.bat myuser/mypassword@[myservice]

Example 2: Running DGN2DB in XFM Mode
 
		%dgn2db% IN_TYPE=XFM IN_FILE=%dgnfile% IN_METADB=%inmetadb% OUT_STORAGE=PostGIS IN_WK=PostGIS IN_WW=PostGIS IN_FEATURE=USStates PSQL_DIR="C:\Program Files\PostgreSQL\12\bin"

This example is based on a Shapefile that has been imported into a DGN File. Review the feature instances in the DGN and their properties in the Data Browser - Because they are recognized as Map Features, they have XFM attributes, as-shown in the Data Browser window. Substitute your data as necessary.

  1. Use Notepad.exe to create a .bat file to import US States from a DGN File.
    @ECHO OFF
    setlocal
    set dgn2db="C:\Program Files\Bentley\Map CONNECT Edition\MapAdvanced\dgn2db.exe"
    set dgndir="C:\ProgramData\Bentley\Map CONNECT Edition\MapAdvanced\Configuration\WorkSpaces\PostGIS\WorkSets\PostGIS\dgn"
    set dgnfile="C:\ProgramData\Bentley\Map CONNECT Edition\MapAdvanced\Configuration\WorkSpaces\PostGIS\WorkSets\PostGIS\dgn\USA.dgn"
    set outstorage=PostGIS
    set workspace=PostGIS
    set workset=PostGIS
    set outdir=%dgndir%\States
    set inmetadb=localhost;5432;PostGIS;postgres;postgres
    %dgn2db% IN_TYPE=XFM IN_FILE=%dgnfile% IN_METADB=%inmetadb% OUT_STORAGE=PostGIS IN_WK=PostGIS IN_WW=PostGIS IN_FEATURE=USStates
    
  2. Execute the .bat file.
  3. Change directories to the EXECUTION_DIR= specified in the Masterload file, the output folder in this case.
  4. Execute the Masterload.BAT file, specifying the PostGIS User and Password.
  5. Create a new connection to the PostGIS database and Query the USStates to review the results.