复制遍历源要素 (Network Analyst)
用法
-
该工具用于在输入网络分析图层未得到求解的情况下求解该图层。如果自上次求解后对输入进行了更改,则会重新求解分析图层。
可为以下网络分析图层生成所遍历的源要素:
- 路径
- 服务区
- 最近设施点
- 车辆配送
不能为以下图层生成遍历的源要素:
- OD 成本矩阵
- 位置分配
输出交汇点要素类不仅包含代表遍历网络交汇点的点,而且还包含代表以下内容的点:
- 所遍历的点障碍
- 所遍历的线障碍和面障碍的进入点和退出点
- 路径分析中的已访问停靠点
- 服务区分析中的已访问设施点和中断结束点
- 最近设施点分析中的已访问设施点和事件点
- 车辆配送分析中的已访问停靠点、站点和中断点
可以通过指定“输出坐标系”环境设置或通过将地理数据库中的要素数据集指定为“输出位置”参数的值来控制输出要素类的坐标系。如果未指定“输出坐标系”环境设置或“输出位置”参数并非要素数据集,则输出要素类的坐标系与输入网络分析图层相同。
语法
CopyTraversedSourceFeatures_na (input_network_analysis_layer, output_location, edge_feature_class_name, junction_feature_class_name, turn_table_name)
参数 | 说明 | 数据类型 |
input_network_analysis_layer |
将复制遍历源要素的网络分析图层。如果网络分析图层没有有效结果,则会通过求解图层以生成有效结果。 | Network Analyst Layer |
output_location |
用来保存输出表和两个要素类的工作空间。 | Workspace; Feature Dataset |
edge_feature_class_name |
将包含遍历边源要素相关信息的要素类的名称。如果求解的网络分析图层不遍历任何边要素,则会创建空要素类。 | String |
junction_feature_class_name |
将包含遍历交汇点源要素(包括输入网络分析图层中的系统交汇点和相关点)相关信息的要素类的名称。如果求解的网络分析图层不遍历任何交汇点,则会创建空要素类。 | String |
turn_table_name |
将包含基础边成本按比例增加的遍历通用转弯和转弯要素相关信息的表的名称。如果求解的网络分析图层不遍历任何转弯,则会创建空表。因为始终不会遍历受限制的转弯,因此它们始终不会包含在输出中。 | String |
代码实例
CopyTraversedSourceFeatures 示例 1(Python 窗口)
以下 Python 窗口脚本演示了如何使用 CopyTraversedSourceFeatures 工具在内存工作空间中将遍历的边、交汇点和转弯从“路径”网络分析图层写入到要素类和表中。
import arcpy
arcpy.na.CopyTraversedSourceFeatures("Route","in_memory",
"TraversedEdges",
"TraversedJunctions",
"TraversedTurns")
CopyTraversedSourceFeatures 示例 2(工作流)
以下独立 Python 脚本演示了如何使用 CopyTraversedSourceFeatures 来查找从人口普查区域质心到最近消防站的路径的共有街道。这些结果有助于确定在紧急情况下使用最为频繁的街道。
# Name: CopyTraversedSourceFeatures_ex02.py
# Description: The scenario shows how to find the streets that are common to the
# routes between the closest fire station and the census tract
# centroids. These streets can be used to identify critical points
# in case of an emergency.
# Requirements: Network Analyst Extension
#Import system modules
import os
import arcpy
from arcpy import env
try:
#Check out the Network Analyst extension license
arcpy.CheckOutExtension("Network")
#Set environment settings
env.workspace = "C:/data/SanFrancisco.gdb"
env.overwriteOutput = True
#Set local variables
inNetworkDataset = "Transportation/Streets_ND"
outNALayerName = "EmergencyRoutes"
impedanceAttribute = "TravelTime"
inFacilities = "Analysis/FireStations"
inIncidents = "Analysis/TractCentroids"
edgeFrequency = "in_memory/EdgeFrequency"
outLayerFile = "C:/data/output" + "/" + outNALayerName + ".lyr"
outFeatures = "CriticalStreets"
#Create a new closest facility analysis layer. For this scenario, the default
#value for all the remaining parameters statisfies the analysis requirements
outNALayer = arcpy.na.MakeClosestFacilityLayer(inNetworkDataset, outNALayerName,
impedanceAttribute, "TRAVEL_FROM")
#Get the layer object from the result object. The closest facility layer can
#now be referenced using the layer object.
outNALayer = outNALayer.getOutput(0)
#Get the names of all the sublayers within the closest facility layer.
subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
#Stores the layer names that we will use later
facilitiesLayerName = subLayerNames["Facilities"]
incidentsLayerName = subLayerNames["Incidents"]
#Load fire station features as facilities and ensure that they are not
#located on restricted portions of the network. Use default field mappings
#and search tolerance
arcpy.na.AddLocations(outNALayer,facilitiesLayerName,inFacilities,"", "",
exclude_restricted_elements = "EXCLUDE")
#Load tract centroids as incidents and ensure that they are not located on
#restricted portions of the network. Map the ID field from Tract Centroids
#as the name for incidents using field mappings
fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, incidentsLayerName)
fieldMappings['Name'].mappedFieldName = "ID"
arcpy.na.AddLocations(outNALayer,incidentsLayerName, inIncidents,
fieldMappings,"", exclude_restricted_elements = "EXCLUDE")
#Solve the closest facility layer and copy the travered source features to a
#temporary in-memory workspace. Use default names for the output feature
#classes and table. Get only the first output which are the edges traversed.
traversedEdges = arcpy.na.CopyTraversedSourceFeatures(outNALayer,
"in_memory").getOutput(0)
#Calculate the frequency of SourceOID in the traversed edges
arcpy.analysis.Frequency(traversedEdges, edgeFrequency,
["SourceOID", "SourceName"])
#Get the full path to the streets feature class by describing the network
#dataset referenced by the network analysis layer.
network = arcpy.Describe(outNALayer.dataSource)
edgeSources = network.edgeSources
for es in edgeSources:
if es.name.lower() == "streets":
streetsSource = os.path.join(os.path.dirname(network.catalogPath),
es.name)
break
else:
raise Exception("Failed to detrmine the path for the streets feature class")
#Join the frequency field to the streets feature class. In order to speed up
#the join select the streets that share a line segment with traversed streets.
streetsLayer = "StreetsLayer"
arcpy.management.MakeFeatureLayer(streetsSource,streetsLayer)
arcpy.management.SelectLayerByLocation(streetsLayer, "SHARE_A_LINE_SEGMENT_WITH",
traversedEdges)
arcpy.management.JoinField(streetsLayer, "ObjectID", edgeFrequency,
"SourceOID", "FREQUENCY")
#Copy the streets that have a frequency value to a new feature class.
arcpy.management.SelectLayerByAttribute(streetsLayer, "SUBSET_SELECTION",
"FREQUENCY IS NOT NULL")
arcpy.management.CopyFeatures(streetsLayer,outFeatures)
#Delete the Frequency field from the streets feature class
arcpy.management.DeleteField(streetsLayer, "FREQUENCY")
#Save the solved na layer as a layer file on disk with relative paths
arcpy.management.SaveToLayerFile(outNALayer,outLayerFile,"RELATIVE")
print "Script completed successfully"
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 occured on line %i" % tb.tb_lineno
print str(e)
相关主题
许可信息
ArcGIS for Desktop Basic: 需要 Network Analyst
ArcGIS for Desktop Standard: 需要 Network Analyst
ArcGIS for Desktop Advanced: 需要 Network Analyst
5/10/2014