ArcGIS Desktop

  • Dokumentation
  • Support

  • My Profile
  • Hilfe
  • Sign Out
ArcGIS Desktop

ArcGIS Online

Die Mapping-Plattform für Ihre Organisation

ArcGIS Desktop

Ein vollständiges professionelles GIS

ArcGIS Enterprise

GIS in Ihrem Unternehmen

ArcGIS for Developers

Werkzeuge zum Erstellen standortbezogener Apps

ArcGIS Solutions

Kostenlose Karten- und App-Vorlagen für Ihre Branche

ArcGIS Marketplace

Rufen Sie Apps und Daten für Ihre Organisation ab.

  • Dokumentation
  • Support
Esri
  • Anmelden
user
  • Eigenes Profil
  • Abmelden

Hilfe

  • Startseite
  • Erste Schritte
  • Karte
  • Analysieren
  • Verwalten von Daten
  • Werkzeuge
  • Mehr ...

Verwenden eines Python-Skripts zum Erstellen des ST_Geometry-Typs in Oracle

Mit der Standard- oder Advanced-Lizenz verfügbar.

Sie können der Oracle-Datenbank den Typ "ST_Geometry", einen Subtype und Funktionen mithilfe eines Python-Skripts hinzufügen, das die ArcPy-Funktion CreateSpatialType aufruft.

In dem Fall wird der Datenbank ein Benutzer mit der Bezeichnung "sde" hinzugefügt. Der SDE-Benutzer besitzt den ST_Geometry-Typ, Subtypes, Funktionen und Tabellen.

In den folgenden Schritten wird erklärt, wie Sie den Typ "ST_Geometry" in einer Oracle-Datenbank mithilfe eines Python-Skripts erstellen:

  1. Kopieren Sie die Bibliothek " libst_shapelib" ("st_shapelib" für Windows) aus dem DatabaseSupport-Verzeichnis in das ArcGIS Client-Installationsverzeichnis, und verschieben Sie sie in einen Speicherort auf dem Oracle-Server.

    Stellen Sie sicher, dass die Bibliothek dem Betriebssystem des Oracle-Servers entsprechend verwendet wird.

    Das Verzeichnis auf dem Server, in dem Sie die Bibliothek ablegen, muss vom Client-Computer, auf dem Sie das Werkzeug Räumlichen Typ erstellen oder das Skript ausführen, zugänglich sein. Wenn Sie die Bibliothek auf einem UNIX- oder Linux-Computer platzieren, müssen Sie sicherstellen, dass der Datenbankadministrator über Lesezugriff auf den Ordner und über Ausführungsberechtigungen für die Bibliotheksdatei verfügt.

  2. Erstellen Sie eine Textdatei auf einem ArcGIS-Client-Computer, und kopieren Sie das folgende Skript in die Datei.
    """
    Name: create_spatial_type.py
    Description: Provide connection information to an Oracle or PostgreSQL database
    and create spatial type in the database.
    Type create_spatial_type.py -h or create_spatial_type.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=['ORACLE', 'POSTGRESQL', ''], default="", help="Type of enterprise DBMS: ORACLE, or POSTGRESQL.")
    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="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 ("-D", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")
    parser.add_option ("-p", dest="Password", type="string", default="", help="SDE user password")
    parser.add_option ("-t", dest="tablespace", type="string", default="", help="Default tablespace for SDE user")
    parser.add_option ("--path", dest="libpath", type="string", default="", help="path to the ST shape library including library file name.")
    
    # 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()
    	password = options.Password 
    	tablespace = options.tablespace
    	database = options.Database.lower()
    	dbms_admin = options.Dbms_admin
    	dbms_admin_pwd = options.Dbms_admin_pwd
    	lib_path = options.libpath
    
    	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)		
    
    	# Local variables
    	instance_temp = instance.replace("\\","_")
    	instance_temp = instance_temp.replace("/","_")
    	instance_temp = instance_temp.replace(":","_")
    	Conn_File_NameT = instance_temp + "_" + database
    	
    	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, instance, 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=dbms_admin, password=dbms_admin_pwd, 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: Create spatial type...
    	try:
    		print "Create spatial type...\n"
    		arcpy.CreateSpatialType_management(input_workspace=Connection_File_Name_full_path, sde_user_password=password, tablespace_name=tablespace, st_shape_library_path=lib_path)
    		print "after spatial type...\n"
    		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)
    
  3. Speichern Sie die Datei mit der Erweiterung .py.
  4. Führen Sie das Skript aus, indem Sie für Ihre Site spezifische Optionen und Informationen bereitstellen.

    Dieses Skript erstellt beispielsweise den Typ "ST_Geometry" in der Oracle-Instanz "oserve/orcl", und die Bibliothek "ST_Geometry" befindet sich im Verzeichnis /ora/shape auf dem Oracle-Server (oserve).

    create_spatial_type.py --DBMS ORACLE -i oserve/orcl --auth DATABASE_AUTH -U sys -P M3tsy$ -p 3$@b0eg -t sde --path /net/oserve/ora/shape/libst_shapelib.so
    

Der ST_Geometry-Typ, Subtypes und Funktionen werden im Schema des SDE-Benutzers erstellt, und in Oracle wird ein Eintrag für die Shape-Bibliothek hinzugefügt.

Wenn Sie mit SQL und der Funktion "ST_Transform" geographische Transformationen durchführen möchten, müssen Sie den Ordner "pedata" aus dem ArcGIS for Desktop-Installationsverzeichnis kopieren, auf dem Oracle-Server platzieren und eine PEDATAHOME-Umgebungsvariable auf dem Server festlegen, die auf dieses Verzeichnis verweist.

ArcGIS Desktop

  • Startseite
  • Dokumentation
  • Support

ArcGIS Plattform

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

Über Esri

  • Über uns
  • Karriere
  • Insider-Blog
  • User Conference
  • Developer Summit
Esri
Wir sind an Ihrer Meinung interessiert.
Copyright © 2018 Esri. | Datenschutz | Rechtliches