摘要
每个输入要素图层或表视图都需要修改各自的工作空间以便连接到所请求的版本。
用法
-
仅适用于要素图层和表视图。
-
该工具不会编辑用于创建输入要素图层或表视图的 ArcSDE 连接文件。仅要素图层/表视图的开放工作空间会更改为连接到所指定的版本。
-
支持事务视图和历史视图。
语法
ChangeVersion_management (in_features, version_type, {version_name}, {date})
参数 | 说明 | 数据类型 |
in_features | 要通过指定版本连接到的要素图层或表视图。 | Feature Layer; Table View |
version_type | 要更改到的版本类型。
| String |
version_name (可选) | 要更改到的版本名称。如果使用的是历史版本,则此项为可选项。 | String |
date (可选) | 要更改到的历史版本的日期。 | Date |
代码实例
ChangeVersion 示例(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 示例(独立脚本)
在典型的版本化分析工作流中使用 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]))
环境
此工具不使用任何地理处理环境