切换版本 (数据管理)

摘要

用于修改图层或表视图的工作空间以连接到指定版本。

使用情况

  • 此工具仅适用于要素图层和表视图。

  • 支持事务和历史视图。

参数

标注说明数据类型
版本名称
(可选)

输入要素图层将连接到的版本的名称。 如果使用历史版本,则此参数为可选参数。

String
日期和时间
(可选)

输入要素图层将连接到的历史版本的日期。

Date

派生输出

标注说明数据类型
输出图层

已更新的输入数据集。

Feature Layer

arcpy.management.ChangeVersion({version_name}, {date})
名称说明数据类型
version_name
(可选)

输入要素图层将连接到的版本的名称。 如果使用历史版本,则此参数为可选参数。

String
date
(可选)

输入要素图层将连接到的历史版本的日期。

Date

派生输出

名称说明数据类型
out_feature_layer

已更新的输入数据集。

Feature Layer

代码示例

ChangeVersion 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 ChangeVersion 函数。

import arcpy
from arcpy import env
env.workspace = r'c:\Connections\toolbox.sde'
arcpy.MakeFeatureLayer_management(r'TOOLBOX.Redlands\TOOLBOX.street','RedlandsStreets')
arcpy.MakeFeatureLayer_management(r'TOOLBOX.Redlands\TOOLBOX.streams','RedlandsStreams')
arcpy.MakeFeatureLayer_management(arcpy.SelectLayerByLocation_management("RedlandsStreams","WITHIN_A_DISTANCE","RedlandsStreets","100 Meters","NEW_SELECTION",'#'),
                                  'StreamsNearStreets','','','')
arcpy.ChangeVersion_management('RedlandsStreets','TRANSACTIONAL', 'TOOLBOX.proposedStreets2k9','')
arcpy.MakeFeatureLayer_management(arcpy.SelectLayerByLocation_management("RedlandsStreams","WITHIN_A_DISTANCE","RedlandsStreets","100 Meters","NEW_SELECTION",'#'),
                                  'NewStreamsNearStreets','','','')
ChangeVersion 示例 2(独立脚本)

在典型的版本化分析工作流中使用 ChangeVersion 函数。

# Name: ChangeVersion.py
# Description: Use the ChangeVersion tool in a typical versioned analysis workflow.
#              Quick check of additional streams within a pre-determined distance
#              of new proposed street development.

# Import system modules 
import arcpy
import sys
import os

# Set environments
arcpy.env.workspace = sys.path[0] + os.sep + "toolbox.sde"

# Create the layers
arcpy.MakeFeatureLayer_management(r'TOOLBOX.Redlands\TOOLBOX.street','RedlandsStreets')
arcpy.MakeFeatureLayer_management(r'TOOLBOX.Redlands\TOOLBOX.streams','RedlandsStreams')

# Perform analysis on the Default version to determine
# current number of streams within 100 meters of streets.
selection1 = arcpy.SelectLayerByLocation_management("RedlandsStreams",
                                                    "WITHIN_A_DISTANCE",
                                                    "RedlandsStreets",
                                                    "100 Meters",
                                                    "NEW_SELECTION",
                                                    '#')
arcpy.MakeFeatureLayer_management(selection1,'StreamsNearStreets','','','')
print("Streams within 100 Meters of current streets: {}".format(
    arcpy.GetCount_management("StreamsNearStreets")[0]))

# Change to the development version
arcpy.ChangeVersion_management('RedlandsStreets',
                               'TRANSACTIONAL',
                               'TOOLBOX.proposedStreets2k9',
                               '')

# Perform the same analysis on the development version to see the effect of the proposed changes.
selection2 = arcpy.SelectLayerByLocation_management("RedlandsStreams",
                                                   "WITHIN_A_DISTANCE",
                                                   "RedlandsStreets",
                                                   "100 Meters",
                                                   "NEW_SELECTION",
                                                   '#')
arcpy.MakeFeatureLayer_management(selection2,'NewStreamsNearStreets','','','')
print("Streams projected to be within 100 Meters of streets after proposed street additions: {}".format(
    arcpy.GetCount_management("NewStreamsNearStreets")[0]))

环境

此工具不使用任何地理处理环境。

相关主题