zoukankan      html  css  js  c++  java
  • 使用PostgreSQL创建、连接企业型地理数据库(完整版)

    如何实现在ArcGIS创建postgresql的企业型地理数据库呢?本教程以arcgis10.2和postgresql9.0为例。

    1、首先得准备好arcgis10.2所能接受型号的postgresql,具体查看官网关于arcgis的配置。

    2、由于所有的arcgis是32位系统的,postgressql是64位系统的那么需从官网上下载:libpq.dll、libintl-8.dll、libiconv-2.dll、libeay32.dll、ssleay32.dll这5个文件,并将其粘贴至arcgis的bin目录下。

    3、修改pg_hba.conf 文件使之允许数据库集群接受远程连接。我的设置如下:

     在IPV4、IPV6各加入一行代码:host all all  0.0.0.0/0 md5 允许数据库链接并md5加密,所不想加密则将所有的md5改为trust

    4、将 st_geometry 库复制到 PostgreSQL 安装目录。可以在 ArcGIS 客户端安装目录的 DatabaseSupport 目录中找到与 PostgreSQL 9.0 配合使用的 st_geometry.dll 文件。将 st_geometry.dll 文件从 ArcGIS 客户端移动到 PostgreSQL 服务器上的 PostgreSQL lib 目录。

    5、创建数据库、sde用户和方案以及地理数据库:

    有几种方法这里以python脚本为例创建,进入Arcdesktop的python窗口输入以下代码:

    """
    Name: create_enterprise_gdb.py
    Description: Provide connection information to a DBMS instance and create an enterprise geodatabase.
    Type  create_enterprise_gdb.py -h or create_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', ''], default="", help="Type of enterprise DBMS:  SQLSERVER, ORACLE, or POSTGRESQL.")                   
    parser.add_option ("-i", dest="Instance", type="string", default="", help="DBMS instance name")
    parser.add_option ("-D", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")
    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="Dbms_admin", type="string", default="", help="DBMS administrator user")
    parser.add_option ("-P", dest="Dbms_admin_pwd", type="string", default="", help="DBMS administrator password")
    parser.add_option ("--schema", dest="Schema_type", type="choice", choices=['SDE_SCHEMA', 'DBO_SCHEMA'], default="SDE_SCHEMA", help="Schema Type for SQL Server geodatabase, SDE or DBO. Default=SDE_SCHEMA")
    parser.add_option ("-u", dest="Gdb_admin", type="string", default="", help="Geodatabase administrator user name")
    parser.add_option ("-p", dest="Gdb_admin_pwd", type="string", default="", help="Geodatabase administrator password")
    parser.add_option ("-t", dest="Tablespace", type="string", default="", help="Tablespace name")
    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
    " % (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
        database = options.Database.lower()    
        account_authentication = options.Account_authentication.upper()
        dbms_admin = options.Dbms_admin
        dbms_admin_pwd = options.Dbms_admin_pwd
        schema_type = options.Schema_type.upper()
        gdb_admin = options.Gdb_admin
        gdb_admin_pwd = options.Gdb_admin_pwd    
        tablespace = options.Tablespace
        license = options.Authorization_file
        
        
        if (database_type == "SQLSERVER"):
            database_type = "SQL_SERVER"
        
        if( database_type ==""):    
            print " 
    %s: error: 
    %s
    " % (sys.argv[0], "DBMS type (--DBMS) must be specified.")
            parser.print_help()
            sys.exit(3)        
            
        if (license == ""):
            print " 
    %s: error: 
    %s
    " % (sys.argv[0], "Authorization file (-l) must be specified.")
            parser.print_help()
            sys.exit(3)            
        
        if(database_type == "SQL_SERVER"):
            if(schema_type == "SDE_SCHEMA" and gdb_admin.lower() != "sde"):
                print "
    %s: error: %s
    " % (sys.argv[0], "To create SDE schema on SQL Server, geodatabase administrator must be SDE.")
                sys.exit(3)
            if (schema_type == "DBO_SCHEMA" and gdb_admin != ""):
                print "
    Warning: %s
    " % ("Ignoring geodatabase administrator specified when creating DBO schema...")
            if( account_authentication == "DATABASE_AUTH" and dbms_admin == ""):
                print "
    %s: error: %s
    " % (sys.argv[0], "DBMS administrator must be specified with database authentication")
                sys.exit(3)
            if( account_authentication == "OPERATING_SYSTEM_AUTH" and dbms_admin != ""):
                print "
    Warning: %s
    " % ("Ignoring DBMS administrator specified when using operating system authentication...")    
        else:
            if (schema_type == "DBO_SCHEMA"):
                print "
    Warning: %s %s, %s
    " % ("Only SDE schema is supported on", database_type, "switching to SDE schema..." )
                
            if( gdb_admin.lower() == ""):
                print "
    %s: error: %s
    " % (sys.argv[0], "Geodatabase administrator must be specified.")
                sys.exit(3)
    
            if( gdb_admin.lower() != "sde"):
                if (database_type == "ORACLE"):
                    print "
    Geodatabase admin user is not SDE, creating user schema geodatabase on Oracle...
    "
                    sys.exit(3)
                else:
                    print "
    %s: error: %s for %s.
    " % (sys.argv[0], "Geodatabase administrator must be SDE", database_type)
                    sys.exit(3)
                
            if( dbms_admin == ""):
                print "
    %s: error: %s
    " % (sys.argv[0], "DBMS administrator must be specified!")
                sys.exit(3)
    
            if (account_authentication == "OPERATING_SYSTEM_AUTH"):
                print "Warning: %s %s, %s
    " % ("Only database authentication is supported on", database_type, "switching to database authentication..." )
    
        # Get the current product license
        product_license=arcpy.ProductInfo()
        
        
        # Checks required license level
        if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
            print "
    " + product_license + " license found!" + " Creating an enterprise geodatabase 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 creating enterprise geodatabase.")
        else:
            print "
    " + product_license + " license available!  Continuing to create..."
            arcpy.AddMessage("+++++++++")
        
        
        try:
            print "Creating enterprise geodatabase...
    "
            arcpy.CreateEnterpriseGeodatabase_management(database_platform=database_type,instance_name=instance, database_name=database, account_authentication=account_authentication, database_admin=dbms_admin, database_admin_password=dbms_admin_pwd, sde_schema=schema_type, gdb_admin_name=gdb_admin, gdb_admin_password=gdb_admin_pwd, tablespace_name=tablespace, authorization_file=license)
            for i in range(arcpy.GetMessageCount()):
                arcpy.AddReturnMessage(i)
            arcpy.AddMessage("+++++++++
    ")
        except:
            for i in range(arcpy.GetMessageCount()):
                arcpy.AddReturnMessage(i)
                
    #Check if no value entered for option    
    except SystemExit as e:
        if e.code == 2:
            parser.usage = ""
            print "
    "
            parser.print_help()   
            parser.exit(2)

    enter运行,运行后选择Toolbox--Data Management Tools--创建企业级地理数据库:

    数据库填充的是在postgres里的数据库名称:默认会有postgres数据库

    管理员密码填充安装postgres你设置的密码

    地理数据管理员密码随便填一个,但这个密码要记住,因为这是sde角色的登录密码

    授权文件是安装Arcserver时使用的密钥。

    此时你已经成功创建了企业型地理数据库,接下来连接你的数据库,点击数据库连接--添加数据库连接:

    创建企业型数据库本机用户实例填:localhost  局域网内访问用户则填创建企业数据库计算机的IP地址

    用户名为sde,密码为之前创建数据库时设置的密码,数据库填你在postgresql中创的数据库。此时,你已经建立好数据库的连接了。接下来postgresql连接你创建企业数据库的本机的方法是:点击文件--添加服务器

    名称和主机名填你所要连接到的服务器IP地址,用户名和密码与之前一致。到此本教程就已结束了,如果觉得解决了你的麻烦的请留个赞吧!!!

  • 相关阅读:
    android:background背景图片被拉伸问题
    面试积累(String和StringBuffer, StringBuilder的理解)
    面试积累(冒泡排序和选择排序)
    面试积累(java的内存分析)
    面试积累(java配置环境变量)
    异常积累(SQLException)
    【linux】fdisk磁盘分区
    【走马观花】十一月十八日通州雨
    【linux】CentOS查看硬件信息
    【linux】go安装及配置
  • 原文地址:https://www.cnblogs.com/HuangDaDa/p/7168675.html
Copyright © 2011-2022 走看看