切换版本 (数据管理)

描述

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

使用方法

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

  • 该工具不会编辑用于创建输入要素图层或表视图的企业级地理数据库连接文件或要素服务。仅输入要素图层或表视图的开放工作空间会更改为连接到所指定的版本。

  • 支持事务视图和历史视图。

语法

ChangeVersion(in_features, version_type, {version_name}, {date})
参数说明数据类型
in_features

将连接到指定版本的要素图层或表视图。

Feature Layer; Table View
version_type

指定输入要素图层将连接到的版本类型。

  • TRANSACTIONAL连接到数据库的一种已定义状态(传统版本)。
  • HISTORICAL连接到表示过去某一特定时刻的版本,通常通过时间标记或历史标记指定。
  • BRANCH连接到分支版本。
String
version_name
(可选)

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

String
date
(可选)

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

Date

派生输出

名称说明数据类型
out_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]))
ChangeVersion 示例 3(独立脚本)

使用 ChangeVersion 函数将要素服务图层更改为指定分支版本。

# Name: ChangeVersionBranchVersioning.py
# Description: Use the ChangeVersion tool to change the branch version of a feature service
#              layer that has the version management capability enabled.

# Import system modules 
import arcpy

# Sign into ArcGIS Enterprise
arcpy.SignInToPortal("https://myserver.mydomain.com/portal", 'portaladmin', 'my.password')

# Create a variable for the feature service URL
myFS = "https://myserver.mydomain.com/server/rest/services/BranchVersioningData/FeatureServer/0"

# Create the layers
arcpy.MakeFeatureLayer_management(myFS, 'myFSLayer')

# Change to a branch version named myVersion
arcpy.ChangeVersion_management('myFSLayer', "BRANCH", "portaladmin.myVersion")

环境

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

许可信息

  • Basic: 否
  • Standard: 是
  • Advanced: 是

相关主题