arcpy.management.Copy(in_data, out_data, {data_type}, {associated_data})
|
名称
|
说明
|
数据类型
|
|
in_data
|
要复制的数据。
|
Data Element
|
|
out_data
|
输出数据的位置和名称。 输出数据的文件扩展名必须与输入数据的扩展名相匹配。 例如,如果要复制文件地理数据库,则输出数据元素的后缀必须为 .gdb。
|
Data Element
|
|
data_type
(可选)
|
磁盘上要复制的数据类型。
仅当两种不同数据类型之间发生名称冲突时才需要此参数。 例如,地理数据库可以包含与要素类同名的关系类。 如果是这种情况,请指定相关关键字。
FeatureClass—如果名称重复,将使用 要素类。
FeatureDataset—如果名称重复,将使用 要素数据集。
MosaicDataset—如果名称重复,将使用 镶嵌数据集。
ParcelFabric—如果名称重复,将使用 宗地结构。
RelationshipClass—如果名称重复,将使用 关系类。
Topology—如果名称重复,将使用 拓扑。
|
String
|
|
associated_data
[[from_name, data_type, to_name, config_keyword],...]
(可选)
|
如果输入具有关联的数据,则此参数可用于控制关联输出数据名称和配置关键字。
如果在 out_data 参数值中未使用 to_name 值,则 from_name 和 to_name 列名称将相同。 如果该名称存在于 out_data 值中,则将通过向 from_name 值附加下划线和数字(例如 rivers_1)来自动创建唯一的 to_name 值。
值表列:
From Name—The data associated with the input data, which will also be copied.
Data Type—The type of the data on disk that will be copied. The only time you need to provide a value is when a geodatabase contains a feature dataset and a feature class with the same name. In this case, use the correct data type, FeatureDataset or FeatureClass, of the item you want to copy.
To Name—The name of the copied data in the output.
Config Keyword—The geodatabase storage parameters (configuration).
|
Value Table
|
代码示例
以下 Python 窗口脚本演示了如何在即时模式下使用 Copy 函数。
import arcpy
arcpy.env.workspace = "C:/data"
arcpy.management.Copy("majorrds.shp", "C:/output/majorrdsCopy.shp")
以下 Python 脚本演示了如何在独立脚本中使用 Copy 函数。
# Name: Copy_Example2.py
# Description: Copy major roads dataset to preserve the original data
# Import system modules
import arcpy
# Set workspace
arcpy.env.workspace = "C:/data"
# Set local variables
in_data = "majorrds.shp"
out_data = "C:/output/majorrdsCopy.shp"
# Run Copy
arcpy.management.Copy(in_data, out_data)
以下 Python 脚本演示了如何在 Copy 函数中使用 associated_data 参数。
# Name: Copy_Example3.py
# Description: Copy a feature dataset and specify associated_data
# Import system modules
import arcpy
# The input is a feature dataset containing 3 feature classes: lakes, cities, rivers
in_data = "C:/data/proj.gdb/mexico"
out_data = "C:/data/proj.sde/mexico"
associated_data = ";".join(["lakes FeatureClass mexico_lakes #",
"cities FeatureClass mexico_cities #",
"rivers FeatureClass mexico_rivers #"])
# Rename each feature class during the copy operation using the associated_data parameter
arcpy.management.Copy(in_data, out_data, associated_data=associated_data)
以下 Python 窗口脚本演示了如何在企业级地理数据库环境中使用 Copy 函数和要素数据集并指定 associated_data 参数。
import arcpy
arcpy.management.Copy(
in_data=r"C:\Users\GIS\SQLServerDatabase.sde\DBO.Mexico",
out_data=r"C:\Users\GIS\SQLServerDatabase.sde\DBO.PyCmd_Mexico",
data_type="FeatureDataset",
associated_data="DBO.Rivers FeatureClass DBO.PyCmd_Rivers #;DBO.Lakes FeatureClass DBO.PyCmd_Lakes #;DBO.Cities FeatureClass DBO.PyCmd_Cities #"
)
以下 Python 脚本演示了如何在企业级地理数据库环境中使用 Copy 函数和要素数据集并指定 associated_data 参数。
# Description: Copy a feature dataset and specify associated_data within an
# Enterprise geodatabase environment
# Import system modules
import arcpy
# The input is a feature dataset containing 3 feature classes: lakes, cities,
# rivers.
in_data = r"C:\Users\GIS\SQLServerDatabase.sde\DBO.Mexico"
# The output is a new feature dataset that the feature classes from in_data will
# be copied to
out_data = r"C:\Users\GIS\SQLServerDatabase.sde\DBO.Py_Mexico"
# Define schema of the from_name and to_name values when preparing data to be
# created in an enterprise geodatabase
associated_data = ";".join(["DBO.Lakes FeatureClass DBO.Py_Lakes #",
"DBO.Cities FeatureClass DBO.Py_Cities #",
"DBO.Rivers FeatureClass DBO.Py_Rivers #"])
# Rename each feature class during the copy operation using the associated_data
# parameter
arcpy.management.Copy(in_data, out_data, associated_data=associated_data)