ArcGIS Desktop

  • 文档
  • 支持

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

Help

  • 主页
  • 入门
  • 制图
  • 分析
  • 管理数据
  • 工具
  • 更多...

Set Data Source

  • 摘要
  • 用法
  • 语法
  • 代码示例
  • 环境
  • 许可信息

摘要

Changes the data source on layers within a map document (MXD).

If you are using one of the standard Defense Mapping templates, you can use this tool to reset the sources of all of the layers in the TOC to the new data source.

用法

  • The Document parameter must be the path to a .mxd on disk and not a map object created with arcpy.mapping.MapDocument().

  • The Data Layer Mapping parameter is a value table that consists of the layer name from the map document and the dataset to which this layer will be resourced.

语法

SetDataSource_defense (document, datalayer_mapping, {active_data_frame_only})
参数说明数据类型
document

The path to a valid ArcMap document (.mxd) that contains layers for which the source needs to be set. This option doesn't work with the CURRENT keyword or a Map Object, so you will need to specify the path.

File
datalayer_mapping
["layer_name", "dataset_path"]

Specifies the layer name and the dataset that corresponds to the layer.

Value Table
active_data_frame_only
(可选)

Determines if the active data frame or all the data frames in the current map should be used to update the sources.

  • ACTIVE_DATA_FRAME_ONLY —Only sources for the active data frame in the map document are updated.
  • ALL_DATA_FRAMES —All of the layers in every data frame in the map document will be resourced. This is the default.
Boolean

代码示例

SetDataSource example 1

This example uses the specific names of the data layers and the proper paths to the datasets.

"""
THIS EXAMPLE ASSUMES THAT YOU KNOW THE SPECIFIC NAMES OF THE DATA
LAYERS AND THE PROPER PATHS TO THE DATASETS.
"""

# Importing necessary modules
import arcpy

# Checking out defense mapping extension
arcpy.CheckOutExtension('defense')

# Setting path to mxd
map_document = r'C:\DATA\Example.mxd'

# Calling Set Data Source tool
arcpy.defense.SetDataSource(map_document, r"'ZD040_Named_Location_Point - TextP' C:\TRD4.gdb\MGCP\TextP")
SetDataSource example 2

This example resets the sources for several layers from a map document to the same dataset.

"""
THIS EXAMPLE ASSUMES THAT YOU ARE RESOURCING SEVERAL LAYERS FROM A MAP
DOCUMENT TO THE SAME DATABASE, AND THAT THERE ARE NO GROUPED LAYERS IN THE
MAP DOCUMENT.
"""

# Importing necessary modules
import arcpy, os

# Checking out defense mapping extension
arcpy.CheckOutExtension('defense')

# Setting path to mxd and database
map_document = r'C:\DATA\Example.mxd'
database = r'C:\DATA\Example.gdb'

# Getting the layers from the proper dataframes
map_object = arcpy.mapping.MapDocument(map_document)
data_frame = arcpy.mapping.ListDataFrames(map_object, "BaseMap")[0]
resource_layers = arcpy.mapping.ListLayers(map_object, "*", data_frame)

# Creating an empty string that we can build onto with each layer in the dataframe
source_string = r""
for layer in resource_layers:
    layer_name = layer.name
    feature_class  = os.path.split(layer.dataSource)[1]
    dataset = os.path.split(os.path.split(layer.dataSource)[0])[1]
    new_source = r'{0}\{1}\{2}'.format(database, dataset, feature_class)
    source_string  = source_string + "'{0}' {1};".format(layer_name, new_source)

# Saving and closing the map document objec to remove any locks
map_object.save()
del map_object

# Running Set Data Source on all layers in the map documents data frame
arcpy.defense.SetDataSource(map_document, source_string)

环境

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

许可信息

  • ArcGIS Desktop Basic: 否
  • ArcGIS Desktop Standard: 需要 Defense Mapping
  • ArcGIS Desktop Advanced: 需要 Defense Mapping

相关主题

  • An overview of the Utilities toolset

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • 内部人员博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2017 Esri. | 隐私政策 | 法律声明