天天看點

怎麼才能實作真正的ArcGIS版本壓縮(Compress)

其實我在今年的開發者大會中專門對ArcGIS版本壓縮做了一個詳細的說明。為什麼專門來說這個呢?其實作在對ArcGIS使用者來說,他們在使用多使用者版本操作時,發現性能慢一般都知道進行ArcGIS版本壓縮,但是他們往往做的就是Compress操作,這樣做是遠遠不夠的,因為什麼都不管隻進行compress操作,不能徹底的進行壓縮,也就是壓縮的不徹底, 那麼标準的ArcGIS版本壓縮流程是什麼樣的呢?

首先說明,理想的版本壓縮後是什麼樣子的

1:不能出錯。(這像是廢話)

2:增量表的資料為空

3:狀态表和族系表一條記錄也就是State_ID=0

相關的壓縮流程,使用專門的管理者使用者

1:斷開其他所有使用者的連接配接,阻止其他新使用者連接配接

2:相關的子版本進行協調和送出

Python實作批量執行ArcGIS版本的協調和送出

http://blog.csdn.net/linghe301/article/details/7777816

3:資料備份(這個和2可以互換順序)

關于ArcGIS資料遷移方案的政策(備份也可以參考)

http://blog.csdn.net/linghe301/article/details/6330759

4:删除相關子版本(注意如果使用過同步複制,注意相關的隐藏子版本)

5:删除相關的鎖資訊

 以oracle 資料庫為例sde使用者下

  • state_locks
  • table_locks
  • object_locks
  • layer_locks

ArcGIS鎖的介紹 http://blog.csdn.net/linghe301/article/details/7345194

6:進行版本壓縮

ArcGIS版本壓縮(Compress)報ORA-00001: unique constraint 的解決方法

http://blog.csdn.net/linghe301/article/details/7331992

ArcSDE版本壓縮之前對UNDO表空間的設定

http://blog.csdn.net/linghe301/article/details/7335530

關于ArcSDE版本壓縮(Compress)的再研究

http://blog.csdn.net/linghe301/article/details/6399036

7:建立子版本

一種快速批量建立子版本的方法

http://blog.csdn.net/linghe301/article/details/7329531

8:重建空間索引

 怎麼對ArcSDE資料庫的要素類進行批量重建空間索引

http://blog.csdn.net/linghe301/article/details/7720871

9:進行統計分析

10:允許其他新使用者連接配接

那麼真正的壓縮隻有這樣才能徹底壓縮幹淨。

那麼我們也可以使用python進行這樣的操作,我沒有經這些環節搞成一個現成可以用的腳本,以下的腳本檔案僅供參考

import arcpy, time, smtplib

# set the workspace 
arcpy.env.workspace = 'Database Connections/admin.sde'

# set a variable for the workspace
workspace = arcpy.env.workspace

# get a list of connected users.
userList = arcpy.ListUsers("Database Connections/admin.sde")

# get a list of usernames of users currently connected and make email addresses
emailList = [u.Name + "@yourcompany.com" for user in arcpy.ListUsers("Database Connections/admin.sde")]

# take the email list and use it to send an email to connected users.
SERVER = "mailserver.yourcompany.com"
FROM = "SDE Admin <[email protected]>"
TO = emailList
SUBJECT = "Maintenance is about to be performed"
MSG = "Auto generated Message.\n\rServer maintenance will be performed in 15 minutes. Please log off."

# Prepare actual message
MESSAGE = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, MSG)

# Send the mail
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, MESSAGE)
server.quit()

#block new connections to the database.
arcpy.AcceptConnections('Database Connections/admin.sde', False)

# wait 15 minutes
time.sleep(900)

#disconnect all users from the database.
arcpy.DisconnectUser('Database Connections/admin.sde', "ALL")

# Get a list of versions to pass into the ReconcileVersions tool.
versionList = arcpy.ListVersions('Database Connections/admin.sde')

# Execute the ReconcileVersions tool.
arcpy.ReconcileVersions_management('Database Connections/admin.sde', "ALL_VERSIONS", "sde.DEFAULT", versionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "DELETE_VERSION", "c:/temp/reconcilelog.txt")

# Run the compress tool. 
arcpy.Compress_management('Database Connections/admin.sde')

#Allow the database to begin accepting connections again
arcpy.AcceptConnections('Database Connections/admin.sde', True)

#Get a list of datasets owned by the admin user

# Get the user name for the workspace
# this assumes you are using database authentication.
# OS authentication connection files do not have a 'user' property.
userName = arcpy.Describe(arcpy.env.workspace).connectionProperties.user

# Get a list of all the datasets the user has access to.
# First, get all the stand alone tables, feature classes and rasters.
dataList = arcpy.ListTables('*.' + userName + '.*') + arcpy.ListFeatureClasses('*.' + userName + '.*') + arcpy.ListRasters('*.' + userName + '.*')

# Next, for feature datasets get all of the featureclasses
# from the list and add them to the master list.
for dataset in arcpy.ListDatasets('*.' + userName + '.*'):
    dataList += arcpy.ListFeatureClasses(feature_dataset=dataset)

# pass in the list of datasets owned by the admin to the rebuild indexes and analyze datasets tools
# Note: to use the "SYSTEM" option the user must be an administrator.
arcpy.RebuildIndexes_management(workspace, "SYSTEM", dataList, "ALL")

arcpy.AnalyzeDatasets_management(workspace, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")
           

以下的壓縮代碼僅供參考,适用于ArcGIS9.2/9.3

# This script is designed to compress an SDE Geodatabase and then
# loop through and analyze the statistics ofeach feature dataset, feature class and table.
# It is designed to log the entire process to a text file and
# if there are any errors during the process the script will email a specified address.
# Created by Mike Long - [email protected]
# Last Modified on 7/16/09

# Import system, Geoprocessing, time and email modules
import sys, string, os, arcgisscripting, time, smtplib

# Set the date.
Date = time.strftime("%m-%d-%Y", time.localtime())

# Set the time.
Time = time.strftime("%I:%M:%S %p", time.localtime())

# Create the Geoprocessor object
gp = arcgisscripting.create()

gp.CheckProduct("ArcEditor") # Checks the license level.
	
gp.SetProduct("arceditor") # Sets the license level.

print "Process started at " + str(Date) + " " + str(Time) + "." + "\n"

# Set up the log file.
LogFile = file('C:\\PythonScripts\\Analyze\\GIS-' + Date + '.txt', 'w') #Creates a log file with todays date.
output = open('C:\\PythonScripts\\Analyze\\GIS-' + Date + '.txt', 'w') #Path to log file.
output.write(str("Process started at " + str(Date) + " " + str(Time) + "." + "\n")) # Write the start time to the log file.


# Load required toolboxes  (This shouldn't need to be changed unless ArcGIS was
#                           installed to a different location)
gp.AddToolbox("F:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

try:
    # Compress the database
    print "Begining Compress..." + "\n"
    gp.toolbox = "management"
    # For this script to work it will need the full path to the .sde connection file.
    gp.compress("C:\\Documents and Settings\\mlong\\Application Data\\ESRI\\ArcCatalog\\[email protected]")
    print gp.GetMessages() + "\n"
    output.write(gp.GetMessages()+ "\n")

except:
    #Sets up the email parameters

    From = "Geoprocessor"
    To = ["[email protected]"] # This is the email address that will receive any errors.
    Date = time.ctime(time.time())
    Subject = "Error Compressing the GIS Database" 
    Text = gp.GetMessages()

    #Format mail message
    mMessage = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n%s\n' %
                (From, To, Date, Subject, Text))
    print 'Connecting to Server'
    s = smtplib.SMTP('machinename.domainname.com') # This needs to be set to your email server.

    #Send Email
    rCode = s.sendmail(From, To, mMessage)
    s.quit()

    if rCode:
        print 'Error Sending Message'
    else:
        print 'Message sent sucessfully'

analyzeworkspace = "C:\\Documents and Settings\\mlong\\Application Data\\ESRI\\ArcCatalog\\Model Connection.sde"

try:
    # Loop through and analyze all Feature datasets
    gp.Workspace = analyzeworkspace
    FCList = gp.ListFeatureClasses ("*", "all")
    FC = FCList.Next()
    while FC:
        gp.Analyze_management(FC, "BUSINESS;FEATURE;ADDS;DELETES")
        print gp.GetMessages() + "\n"
        output.write(gp.GetMessages()+ "\n")
        FC = FCList.Next()
    # Loop through and analyze all the Feature classes
    gp.Workspace = analyzeworkspace
    FDList = gp.ListDatasets ("*", "all")
    FD = FDList.Next()
    while FD:
        gp.Analyze_management(FD, "BUSINESS;FEATURE;ADDS;DELETES")
        print gp.GetMessages() + "\n"
        output.write(gp.GetMessages())
        FD = FDList.Next()
    # Loop through and analyze all the Tables.
    # The if-else statements set the script to skip over Multi-Versioned Views.
    gp.Workspace = analyzeworkspace
    TBList = gp.ListTables ("*", "all")
    TB = TBList.Next()
    while TB:
        if '_MVVIEW' in TB:
            print "Skipping Multi-Versioned View"
        elif '_MVView' in TB:
            print "Skipping Multi-Versioned View"
        else:
            gp.Analyze_management(TB, "BUSINESS;FEATURE;ADDS;DELETES")
            print gp.GetMessages() + "\n"
            output.write(gp.GetMessages())
        TB = TBList.Next()

except:
    print gp.GetMessages()
    output.write(gp.GetMessages())

    #Sets up the email parameters

    From = "Geoprocessor"
    To = ["[email protected]"]
    Date = time.ctime(time.time())
    Subject = "Error Analyzing the GIS Database"
    Text = gp.GetMessages()

    #Format mail message
    mMessage = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n%s\n' %
                (From, To, Date, Subject, Text))
    print 'Connecting to Server'
    s = smtplib.SMTP('machinename.domainname.com')

    #Send Email
    rCode = s.sendmail(From, To, mMessage)
    s.quit()

    if rCode:
        print 'Error Sending Message'
    else:
        print 'Message sent sucessfully'

# Sets the Date & Time since the script started.
Date = time.strftime("%m-%d-%Y", time.localtime())# Set the date.
Time = time.strftime("%I:%M:%S %p", time.localtime()) # Set the time.
output.write(str("Process completed at " + str(Date) + " " + str(Time) + "." + "\n")) # Write the start time to the log file.

output.close() # Closes the log file.

print "Process completed at " + str(Date) + " " + str(Time) + "."
           

Esri 相關系列文章:

怎麼才能實作真正的ArcGIS版本壓縮(Compress)
   HowTo:  Automate reconcile, post and compress processes

 -------------------------------------------------------------------------------------------------------

版權所有,文章允許轉載,但必須以連結方式注明源位址,否則追究法律責任!

-------------------------------------------------------------------------------------------------------