描述
使用输入模板文件 (.xml) 中包含的方案创建新的网络数据集。在执行该工具之前,必须确保创建网络数据集所需的所有要素类和输入表已经存在。
使用
- 该工具会使用模板文件中的方案创建新的网络数据集。使用从网络数据集创建模板工具为新的网络数据集创建方案。输入模板文件中对输出网络数据集的名称进行了指定。 
- 新创建的网络数据集将需要使用构建网络工具进行构建。 
语法
CreateNetworkDatasetFromTemplate(network_dataset_template, output_feature_dataset)
| 参数 | 说明 | 数据类型 | 
| network_dataset_template | 使用从网络数据集创建模板工具创建的模板文件 (.xml) 中包含要创建的输出网络数据集方案。 | File | 
| output_feature_dataset | 要素数据集中包含将加入所创建的网络数据集的要素类。将根据网络数据集模板中指定的名称在此数据集中创建网络。 | Feature Dataset | 
派生输出
| 名称 | 说明 | 数据类型 | 
| output_network | 使用输入模板文件中包含的方案的新网络数据集。 | 网络数据集 | 
代码示例
CreateNetworkDatasetFromTemplate 示例 1(Python 窗口)
使用所有参数执行此工具。
new_network_location = "C:/data/NewNetwork.gdb/Transportation"
xml_template = "C:/data/NDTemplate.xml"
arcpy.na.CreateNetworkDatasetFromTemplate(new_network_location, xml_template)
CreateNetworkDatasetFromTemplate 示例 2(独立脚本)
以下独立 Python 脚本演示了如何使用 CreateNetworkDatasetFromTemplate 工具通过现有模板创建新的网络数据集。
# Name: NetworkDatasetTemplate_workflow.py
# Description: Create a new network dataset with the same schema as an existing
#               network dataset
# Requirements: Network Analyst Extension
#Import system modules
import arcpy
import os
try:
    #Check out Network Analyst license if available. Fail if the Network Analyst license is not available.
    if arcpy.CheckExtension("network") == "Available":
        arcpy.CheckOutExtension("network")
    else:
        raise arcpy.ExecuteError("Network Analyst Extension license is not available.")
    
    #Set local variables
    original_network = "C:/data/Region1.gdb/Transportation/Streets_ND"
    new_network_location = "C:/data/Region2.gdb/Transportation"
    xml_template = "C:/data/NDTemplate.xml"
    
    #Create an XML template from the original network dataset
    arcpy.na.CreateTemplateFromNetworkDataset(original_network, xml_template)
    #Create the new network dataset in the output location using the template.
    #The output location must already contain feature classes and tables with 
    #the same names and schema as the original network.
    arcpy.na.CreateNetworkDatasetFromTemplate(xml_template,
                                                new_network_location)
    
    #Build the new network dataset
    arcpy.na.BuildNetwork(os.path.join(new_network_location, "Streets_ND"))
except Exception as e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print(("An error occurred on line %i" % tb.tb_lineno))
    print((str(e)))
环境
许可信息
- Basic: 需要 Network Analyst
- Standard: 需要 Network Analyst
- Advanced: 需要 Network Analyst