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

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

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.

構文

arcpy.defense.SetDataSource(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)

環境

このツールは、ジオプロセシング環境を使用しません。

ライセンス情報

  • Basic: いいえ
  • Standard: 次のものが必要 Defense Mapping
  • Advanced: 次のものが必要 Defense Mapping

関連トピック

  • An overview of the Utilities toolset

ArcGIS Desktop

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

ArcGIS

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

Esri について

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