使用脚本在 Linux、UNIX 或 Windows 上的 DB2 中创建地理数据库
您可以复制并修改示例脚本以便在 Linux、UNIX 或 Windows 上的现有 IBM DB2 数据库中创建地理数据库。
在运行脚本之前必须完成一些附加任务。以下步骤对这些任务和脚本自身进行了介绍:
步骤:
- 在服务器上安装并配置 DB2。
- 在 DB2 服务器上创建名为 sde 的操作系统登录。
- 将 sde 用户添加到具有 SYSMON 权限的组。
- 创建一个数据库并注册到 Spatial Extender。
- 将数据库上的 DBADM 授予 sde 用户。
- 如果要从 DB2 服务器以外的计算机运行 Python 脚本,请在将要运行脚本的计算机上安装并配置 DB2 客户端。
DB2 客户端安装程序可从 Esri 客户关怀中心门户网站下载。如果安装 DB2 客户端运行 32 位 ArcGIS 客户端,则安装 32 位版本的 DB2 客户端。如果安装 DB2 客户端运行 ArcGIS 服务器,则安装 64 位版本的 DB2 客户端。有关详细信息,请参阅设置到 DB2 的连接。
- 将示例脚本复制到已安装 ArcGIS Desktop(ArcEditor 或 ArcInfo)、ArcGIS Server(标准版或高级版)、或 ArcGIS Engine 及 Geodatabase Update 扩展模块的 ArcGIS Desktop 或任意 Python IDE(例如 PythonWin 或 WING)的 Python 窗口中。
此示例脚本在现有 DB2 数据库中启动地理数据库功能:
""" Name: enable_enterprise_gdb.py Description: Provide connection information to an enterprise database and enable enterprise geodatabase. Type enable_enterprise_gdb.py -h or enable_enterprise_gdb.py --help for usage Author: Esri """ # Import system modules import arcpy, os, optparse, sys # Define usage and version parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0 for " + arcpy.GetInstallInfo()['Version'] ) #Define help and options parser.add_option ("--DBMS", dest="Database_type", type="choice", choices=['SQLSERVER', 'ORACLE', 'POSTGRESQL', 'DB2','INFORMIX','DB2ZOS', ''], default="", help="Type of enterprise DBMS: SQLSERVER, ORACLE, POSTGRESQL, DB2, INFORMIX, or DB2ZOS.") parser.add_option ("-i", dest="Instance", type="string", default="", help="DBMS instance name") parser.add_option ("--auth", dest="account_authentication", type ="choice", choices=['DATABASE_AUTH', 'OPERATING_SYSTEM_AUTH'], default='DATABASE_AUTH', help="Authentication type options (case-sensitive): DATABASE_AUTH, OPERATING_SYSTEM_AUTH. Default=DATABASE_AUTH") parser.add_option ("-u", dest="User", type="string", default="", help="Geodatabase administrator user name") parser.add_option ("-p", dest="Password", type="string", default="", help="Geodatabase administrator password") parser.add_option ("-D", dest="Database", type="string", default="none", help="Database name: Not required for Oracle") parser.add_option ("-l", dest="Authorization_file", type="string", default="", help="Full path and name of authorization file") # Check if value entered for option try: (options, args) = parser.parse_args() #Check if no system arguments (options) entered if len(sys.argv) == 1: print "%s: error: %s\n" % (sys.argv[0], "No command options given") parser.print_help() sys.exit(3) #Usage parameters for spatial database connection database_type = options.Database_type.upper() instance = options.Instance account_authentication = options.account_authentication.upper() username = options.User.lower() password = options.Password database = options.Database.lower() license = options.Authorization_file if( database_type ==""): print " \n%s: error: \n%s\n" % (sys.argv[0], "DBMS type (--DBMS) must be specified.") parser.print_help() sys.exit(3) if (license == ""): print " \n%s: error: \n%s\n" % (sys.argv[0], "Authorization file (-l) must be specified.") parser.print_help() sys.exit(3) if (database_type == "SQLSERVER"): database_type = "SQL_SERVER" # Get the current product license product_license=arcpy.ProductInfo() if (license == ""): print " \n%s: error: %s\n" % (sys.argv[0], "Authorization file (-l) must be specified.") parser.print_help() sys.exit(3) # Checks required license level if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE': print "\n" + product_license + " license found!" + " Enabling enterprise geodatabase functionality requires an ArcGIS for Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS for Server license." sys.exit("Re-authorize ArcGIS before enabling an enterprise geodatabase.") else: print "\n" + product_license + " license available! Continuing to enable..." arcpy.AddMessage("+++++++++") # Local variables instance_temp = instance.replace("\\","_") instance_temp = instance_temp.replace("/","_") instance_temp = instance_temp.replace(":","_") Conn_File_NameT = instance_temp + "_" + database + "_" + username if os.environ.get("TEMP") == None: temp = "c:\\temp" else: temp = os.environ.get("TEMP") if os.environ.get("TMP") == None: temp = "/usr/tmp" else: temp = os.environ.get("TMP") Connection_File_Name = Conn_File_NameT + ".sde" Connection_File_Name_full_path = temp + os.sep + Conn_File_NameT + ".sde" # Check for the .sde file and delete it if present arcpy.env.overwriteOutput=True if os.path.exists(Connection_File_Name_full_path): os.remove(Connection_File_Name_full_path) print "\nCreating Database Connection File...\n" # Process: Create Database Connection File... # Usage: out_file_location, out_file_name, DBMS_TYPE, instnace, database, account_authentication, username, password, save_username_password(must be true) arcpy.CreateDatabaseConnection_management(out_folder_path=temp, out_name=Connection_File_Name, database_platform=database_type, instance=instance, database=database, account_authentication=account_authentication, username=username, password=password, save_user_pass="TRUE") for i in range(arcpy.GetMessageCount()): if "000565" in arcpy.GetMessage(i): #Check if database connection was successful arcpy.AddReturnMessage(i) arcpy.AddMessage("\n+++++++++") arcpy.AddMessage("Exiting!!") arcpy.AddMessage("+++++++++\n") sys.exit(3) else: arcpy.AddReturnMessage(i) arcpy.AddMessage("+++++++++\n") # Process: Enable geodatabase... try: print "Enabling Enterprise Geodatabase...\n" arcpy.EnableEnterpriseGeodatabase_management(input_database=Connection_File_Name_full_path, authorization_file=license) for i in range(arcpy.GetMessageCount()): arcpy.AddReturnMessage(i) arcpy.AddMessage("+++++++++\n") except: for i in range(arcpy.GetMessageCount()): arcpy.AddReturnMessage(i) if os.path.exists(Connection_File_Name_full_path): os.remove(Connection_File_Name_full_path) #Check if no value entered for option except SystemExit as e: if e.code == 2: parser.usage = "" print "\n" parser.print_help() parser.exit(2)
- 修改此脚本以包含特定于您的站点的信息。
- 运行您复制和更改的脚本。
用于地理数据库创建的日志文件 (GDBCreateGeodatabase<#>.log) 会写入运行此脚本的计算机上 TEMP 或 TMP 变量所指定的目录。
相关主题
5/10/2014