ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • ヘルプ
  • Sign Out
ArcGIS Desktop

ArcGIS Online

組織のマッピング プラットフォーム

ArcGIS Desktop

完全なプロ仕様の GIS

ArcGIS Enterprise

エンタープライズ GIS

ArcGIS Developers

位置情報利用アプリの開発ツール

ArcGIS Solutions

各種業界向けの無料のテンプレート マップおよびテンプレート アプリケーション

ArcGIS Marketplace

組織で使えるアプリとデータを取得

  • ドキュメント
  • サポート
Esri
  • サイン イン
user
  • マイ プロフィール
  • サイン アウト

ArcMap

  • ホーム
  • はじめに
  • マップ
  • 解析
  • データ管理
  • ツール
  • エクステンション

同期対応データのリコンサイル処理とポスト処理の自動化

  • サービス名に基づくジオデータベース バージョンの特定
  • バージョンのバッチ リコンサイルと変更内容のポスト
  • ジオデータベースの圧縮
  • インデックスの再構築と統計情報の更新
  • レプリカによって参照されなくなったバージョンの削除
  • 完全なコードの例

ArcGIS ジオデータベース管理者は、Python スクリプトを使用して、通常は複数のジオプロセシング ツールを使用して実行する多数のタスクを自動化できます。このトピックでは、フィールド スタッフがバージョン対応登録されたデータに対する編集を同期させた後、管理者が夜間にスケジュールされたバージョンのリコンサイルを実行するプロセスについて説明します。

サービス名に基づくジオデータベース バージョンの特定

# Create a list of user names that will be used to find versions.
userList = ['???', '###']
# Get a list of versions for the service named '???' and '###' to pass into the ReconcileVersions tool.
versions = arcpy.da.ListVersions('//connectionLocation/admin.sde')
# Create an empty list that will be used to hold version names that we want to reconcile.
verReconcileList = []
# Loop through the versions list to look for versions with appropriate names.
# if these names are found append them to the verReconcileList.
for user in userList:
    for version in versions:
        if user.lower() in version.name.lower():
            verReconcileList.append(version.name)

バージョンのバッチ リコンサイルと変更内容のポスト

[バージョンのリコンサイル (Reconcile Versions)] ツールを使用して、エンタープライズ ジオデータベースのすべてのバージョンをリコンサイルしてポストできます。このツールを使用して、ジオデータベース内のすべてのバージョン (ALL_VERSIONS)、またはターゲット バージョンを圧縮からブロックしているバージョン (BLOCKING_VERSIONS) のみを、ターゲット バージョンにリコンサイルできます。このツールを使用すると、一度に複数のバージョンを適切な順序でリコンサイルしてポストできるため、圧縮を効率的に実行できます。また、リコンサイル処理またはポスト処理の後、DELETE_VERSION キーワードを指定してバージョンを削除することもできます。この例では、ジオデータベース管理者としてツールを実行しています。ジオデータベース管理者として接続すると、ジオデータベース内のすべてのバージョンだけでなく、他のユーザーが保有しているプライベートのバージョンやプロテクトのバージョンもリコンサイルしてポストできます。

# Get a list of versions to pass into the ReconcileVersions tool. versionList = arcpy.ListVersions('//connectionLocation/admin.sde')
# Execute the ReconcileVersions tool.
arcpy.ReconcileVersions_management('//connectionLocation/admin.sde', "ALL_VERSIONS", "sde.DEFAULT", verReconcileList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION", "c:/temp/reconcilelog.txt")

ジオデータベースの圧縮

リコンサイルと変更内容のポストが完了したら、ジオデータベースを圧縮して重複する情報を削除し、編集をビジネス テーブルに移行することが重要です。

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

インデックスの再構築と統計情報の更新

圧縮操作を実行した後、インデックスを再構築し、統計情報を更新することをお勧めします。これらの手順は、[インデックスの再構築 (Rebuild Indexes)] ツールと [データセットの分析 (Analyze Datasets)] ツールを使用して実行できます。これらのツールでは、データセットのリストの入力が可能であり、すべてのデータセットで同時に関数を実行します。これらのツールをジオデータベース管理者で実行すると、該当するシステム テーブルの統計情報が更新され、インデックスが再構築されます。このプロセスでは、まず、データのリストおよびそれらのデータを所有するユーザーのリストを取得します。インデックスと統計情報は、データの所有者のみが更新できます。

# set the workspace arcpy.env.workspace = '//connectionLocation/dataOwner.sde'
# 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 owned by the current user. oDataList = arcpy.ListTables('*.' + userName + '.*') + arcpy.ListFeatureClasses('*.' + userName + '.*') + arcpy.ListRasters('*.' + userName + '.*')
# Next, for feature datasets owned by the current user
# get all of the featureclasses and add them to the master list. for dataset in arcpy.ListDatasets('*.' + userName + '.*'):
    oDataList += arcpy.ListFeatureClasses(feature_dataset=dataset)
注意:

ユーザーが所有するデータセットを制限するために使用されるワイルドカード トークンはオペレーティング システムに固有です。上の例 ('*.' + userName + '.*') は、SQL Server、PostgreSQL、または DB2 で動作します。Oracle の場合、ワイルドカードとして (userName + '.*') を使用できます。Informix の場合、ワイルドカードとして ('*:' + userName + '.*') を使用できます。

ユーザーが所有するデータのリストを特定した後、そのリストを [インデックスの再構築 (Rebuild Indexes)] ツールと [データセットの分析 (Analyze Datasets)] ツールに渡すことができます。

データの所有者が複数存在する場合、データ所有者ごとにデータ リストを生成する必要があります。データ所有者ごとに接続して、[インデックスの再構築 (Rebuild Indexes)] ツールと [データセットの分析 (Analyze Datasets)] ツールを実行します。

# Execute rebuild indexes and analyze datasets
# Note: to use the "SYSTEM" option, the user must be an administrator.
workspace = "//connectionLocation/user1.sde"
arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", oDataList, "ALL")
arcpy.AnalyzeDatasets_management(workspace, "NO_SYSTEM", oDataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")

レプリカによって参照されなくなったバージョンの削除

# set the workspace workspace = '//connectionLocation/admin.sde'
# Get a list of all the replica versions in the geodatabase replicaVersions = [replica.version for replica in arcpy.da.ListReplicas(workspace)]
# Loop through this replica version list and remove these version names from the list of versions we reconciled earlier. # We want to remove versions from this list that are still being referenced by a replica for replicaVer in replicaVersions:
  if replicaVer in verReconcileList:
    verReconcileList.remove(replicaVer)
# Loop through the verReconcileList and delete versions. 
# These versions are no longer being referenced by a replica so we can assume it's safe to delete them. if len(versionsList) > 0:
  for version in verReconcileList:
  		arcpy.DeleteVersion_management(workspace, version)

完全なコードの例

以下のコード例では、上記のすべての項目を組み合わせて次の操作を実行します。

  • ジオデータベースのバージョンを特定します。
  • バージョンのリコンサイルと変更内容のポストを行います。
  • ジオデータベースを圧縮します。
  • システム テーブルのインデックスを再構築し、統計情報を更新します。
  • ユーザー テーブルのインデックスを再構築し、統計情報を更新します。

注意:

次に示すスクリプトには、このトピックの他のコード サンプルと比較して、追加のロジックが含まれています。この追加のロジックは、エラー状況をより効率的に処理するためのものです。また、次のスクリプトでは、コメントと変数名の一部が変更されている点にも注意してください。

import arcpy

try:
    # Set the workspace 
    arcpy.env.workspace = 'Database Connections/admin.sde'
    
    # Set variables
    workspace = arcpy.env.workspace
    arcpy.env.overwriteOutput = True
    targetVersion = 'sde.DEFAULT'
    
    # Create a list of user names that will be used to find versions.
    userList = ['???', '###']
    
    # Get a list of versions for the service named '???' and '###' to pass into the ReconcileVersions tool.
    versions = arcpy.da.ListVersions(workspace)
    
    # Create an empty list that will be used to hold version names that we want to reconcile.
    verReconcileList = []
    
    # Loop through the list to look for versions with our user names in their name where the parent version is the target version.
    # if these names are found append them to the verReconcileList.
    for user in userList:
        for version in versions:
            if user.lower() in version.name.lower():
                if version.parentVersionName.lower() == targetVersion.lower():
                    verReconcileList.append(version.name)
    
    # Perform maintenance if versions are found, otherwise there is no maintenance to perform.
    if len(verReconcileList)>0:
        
        # Execute the ReconcileVersions tool.
        arcpy.ReconcileVersions_management(workspace, "ALL_VERSIONS", targetVersion, verReconcileList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION", "c:/temp/reconcilelog.txt")
        
        # Run the compress tool. 
        arcpy.Compress_management(workspace)
        
        # Rebuild indexes and analyze the states and states_lineages system tables
        arcpy.RebuildIndexes_management(workspace, "SYSTEM", "", "ALL")
        
        arcpy.AnalyzeDatasets_management(workspace, "SYSTEM", "", "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")
        
        
        '''
        *********************
        Data Owner(s) Section
        *********************
        '''
        # Get a list of datasets owned by the data owner user (requires second connection file)
        
        # Set the workspace 
        arcpy.env.workspace = 'Database Connections/dataOwner.sde'
        
        # Set a variable for the workspace
        workspace = arcpy.env.workspace
        
        # 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 owned by the current user.
        oDataList = arcpy.ListTables('*.' + userName + '.*') + arcpy.ListFeatureClasses('*.' + userName + '.*') + arcpy.ListRasters('*.' + userName + '.*')
        
        # Next, for feature datasets owned by the current user
        # get all of the featureclasses and add them to the master list.
        for dataset in arcpy.ListDatasets('*.' + userName + '.*'):
            oDataList += arcpy.ListFeatureClasses(feature_dataset=dataset)
        
        # Rebuild indexes and analyze the data owner tables
        arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", oDataList, "ALL")
        
        arcpy.AnalyzeDatasets_management(workspace, "NO_SYSTEM", oDataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")
        
        '''
        *************************
        End Data Owner(s) Section
        *************************
        '''
        
        # set the workspace back to the admin workspace
        workspace = 'Database Connections/admin.sde'
        
        # Get a list of all the replica versions in the geodatabase
        replicaVersions = [replica.version for replica in arcpy.da.ListReplicas(workspace)]
        
        '''
        - We now have a list of versions that were created by taking a map offline (verReconcileList)
        - We also have a list of replica versions (replicaVersions)
        - The versions that we were reconciling are ready to be deleted if they are not currently pointing to a version
        - We are going to loop through the reconcile versions list and remove any versions that are still pointing to a replica
        - The versions remaining in the reconcile list are ready to be cleaned (deleted) up because there are no maps/replicas pointing to them. 
        '''
        
        # Using the list of versions associated with users/maps that we reconciled earlier. Remove any versions from the list that are still being used by a replica. 
        for replicaVer in replicaVersions:
            if replicaVer in verReconcileList:
                verReconcileList.remove(replicaVer)
        
        # Loop through the versionsList and delete versions that are no longer being referenced by a replica. 
        # Since these versions are no longer being referenced by a replica we can assume it's safe to delete them.
        if len(verReconcileList) > 0:     #check to see that the list is not empty
            for version in verReconcileList:
                try:
                    arcpy.DeleteVersion_management(workspace, version)
                except:
                    print("Failed to delete version.")
                    print(arcpy.GetMessages(2))
        else:
            print("No versions to delete.")
    
    else:
        print("No versions to reconcile, aborting version maintenance routine.")

except:
    print(arcpy.GetMessages(2))
    
print("Done.")

ArcGIS Desktop

  • ホーム
  • ドキュメント
  • サポート

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

Esri について

  • 会社概要
  • 採用情報
  • Esri ブログ
  • ユーザ カンファレンス
  • デベロッパ サミット
Esri
ご意見・ご感想をお寄せください。
Copyright © 2021 Esri. | プライバシー | リーガル