摘要
提供网络数据集属性的访问权限。 您可以使用此类检索网络数据集边、交汇点和转弯的属性和属性值,以及网络数据集的其他属性。
语法
NetworkDataset (in_network)
参数 | 说明 | 数据类型 |
in_network | 要检索其属性的网络数据集。可以使用网络数据集的目录路径、网络数据集图层对象或网络数据集图层的字符串名称来指定参数。 | String |
属性
属性 | 说明 | 数据类型 |
buildTimestamp (只读) | 最近构建的网络数据集的日期和时间。 | DateTime |
customEvaluators (可读写) | 用于在求解操作中自定义边、交汇点和转弯的网络属性值的 Python 类列表。 必须将属性指定为从 arcpy.nax.AttributeEvaluator 类继承的用户定义类的实例列表。 自定义赋值器类不能使用此属性与网络数据集永久关联。 关联是临时的,仅适用于设置了此属性的同一脚本中的求解操作。 若要永久保留与自定义赋值器类的关联,请使用 updateNetworkDatasetSchema 方法。 | Object |
directionsCustomizer (可读写) | 在求解操作中使用网络数据集时,用于对返回的方向行进策略文本进行自定义的 Python 类。 必须将属性指定为从 arcpy.nax.DirectionsCustomizer 类继承的用户定义类的实例。 自定义方向类不能使用此属性与网络数据集永久关联。 关联是临时的,仅适用于设置了此属性的同一脚本中的求解操作。 若要永久保留与自定义方向类的关联,请使用 updateNetworkDatasetSchema 方法。 | Object |
edgeCount (只读) | 网络中的边数。 | Integer |
isBuilt (只读) | 指定是否构建网络数据集。 值 False 表示必须重建网络数据集才能合并更改。 | Boolean |
junctionCount (只读) | 网络中的交汇点数。 | Integer |
travelModes (只读) | 返回适用于网络数据集的出行模式对象的字典。 字典关键字是出行模式的名称,字典值是出行模式对象。 此属性与 GetTravelModes 函数所返回的输出相同。 | Dictionary |
turnCount (只读) | 网络中的转弯数。 | Integer |
方法概述
方法 | 说明 |
checkIntersectingFeatures (feature_layer, cutoff) | 返回一个布尔值,指示指定的网络数据集内与指定的要素图层中的要素相交的边源要素的数量是小于还是等于指定中断。对于可作为线障碍或面障碍加载到网络分析问题的要素,该选项有助于限制其数量。 此方法与 CheckIntersectingFeatures 函数类似。 |
describe () | 将返回包含网络数据集其他属性的 Describe 对象。这等同于使用网络数据集上的 arcpy.Describe。 |
edges ({edge_properties}, {attribute_names}, {time_of_day}, {eids}, {travel_mode}, {area_of_interest}) | 返回网络数据集边元素的迭代器,您可用其在一天内的指定时间访问特定边属性和网络属性的值。 |
getDataSourceFromSourceID (source_id) | 返回由给定源 ID 标识的网络数据集源要素类的目录路径。 提示:此方法瞬时生效,因为它将读取已缓存值。 代码可以重复调用此方法,并尽可能降低性能影响。 |
junctions ({junction_properties}, {attribute_names}, {time_of_day}, {eids}, {travel_mode}, {area_of_interest}) | 返回网络数据集交汇点元素的迭代器,您可用其在一天内的指定时间访问特定交汇点属性和网络属性的值。 |
turns ({turn_properties}, {attribute_names}, {eids}, {travel_mode}, {area_of_interest}) | 返回网络数据集转弯元素的迭代器,您可用其访问特定转弯属性和网络属性的值。 |
updateNetworkDatasetSchema ({custom_evaluators}, {custom_directions}) | 更新网络数据集,以将自定义赋值器或方向 Python 类与网络相关联。 |
方法
checkIntersectingFeatures (feature_layer, cutoff)
参数 | 说明 | 数据类型 |
feature_layer | Layer 对象包含与网络边源相交的要素。支持图层对象上存在的所有选择集或定义查询,且仅可用于指定要素的某个子集。 | Layer |
cutoff | 相交要素的最大数量。 | Integer |
数据类型 | 说明 |
Boolean | 如果相交要素的数量小于或等于 cutoff 值,则返回 True。如果相交要素的数量超出 cutoff 值,则返回 False。 |
edges ({edge_properties}, {attribute_names}, {time_of_day}, {eids}, {travel_mode}, {area_of_interest})
参数 | 说明 | 数据类型 |
edge_properties [edge_properties,...] | A list of strings representing the network edge properties to retrieve. For a single property, you can use a string instead of a list of strings. The available properties include the following:
To request the ISRESTRICTED, COST, TIME, and DISTANCE properties, you must specify a value for the travel_mode parameter. | String |
attribute_names [attribute_names,...] | The list of network dataset attribute names, such as costs or restrictions, for which to retrieve the value for each network element. If the value is time dependent, you can specify the time of day using the time_of_day parameter. For a single attribute, you can use a string instead of a list of strings. | String |
time_of_day | The time of day for which to retrieve time-dependent attribute values for this network element. When no time of day value is passed, the time-neutral value will be returned. | DateTime |
eids [eids,...] | A list of EID values to include in the cursor. This allows you to return only a subset of all network elements. If no value is passed for this parameter, all network elements are returned. The eids and area_of_interest parameters cannot be used simultaneously. | Integer |
travel_mode | The travel mode to apply when requesting edge properties and attribute values. The travel mode settings may impact the returned property and attribute values, particularly if the travel mode uses nondefault values for any attribute parameters. When no travel mode is specified, all values requested from attribute_names use their default attribute parameter values, and the ISRESTRICTED, COST, TIME, and DISTANCE properties are not available. The travel mode should be specified as a TravelMode object. You can use one of the network's travel modes obtained using the NetworkDataset object's travelModes property or use a custom TravelMode object. | Object |
area_of_interest | The spatial filter to apply when requesting edge properties and attribute values. This allows you to return only the subset of edges that intersect the specified area of interest. The parameter should be specified as an Extent object or a Polygon object. If an Extent object is used, all edges intersecting the rectangular extent are returned. If a Polygon object is used, all edges intersecting the polygon's shape are returned. The Polygon option can be used to filter edges by country or state boundaries, for example. If a 3D polygon is used, all edges intersecting the 2D projection of the polygon are returned. The eids and area_of_interest parameters cannot be used simultaneously. | Object |
数据类型 | 说明 |
Object | 用于迭代所返回的边的 NetworkDatasetEdgeCursor 对象。 每行均是一组该边 edge_properties 和 attribute_names 参数中指定项目的值。 |
getDataSourceFromSourceID (source_id)
参数 | 说明 | 数据类型 |
source_id | The network source ID for which the corresponding source feature class's catalog path will be retrieved. | Integer |
数据类型 | 说明 |
String | 网络数据集源要素类的目录路径。 |
junctions ({junction_properties}, {attribute_names}, {time_of_day}, {eids}, {travel_mode}, {area_of_interest})
参数 | 说明 | 数据类型 |
junction_properties [junction_properties,...] | A list of strings representing the network junction properties to retrieve. For a single property, you can use a string instead of a list of strings. The available properties include the following:
To request the ISRESTRICTED, COST, TIME, and DISTANCE properties, you must specify a value for the travel_mode parameter. | String |
attribute_names [attribute_names,...] | The list of network dataset attribute names, such as costs or restrictions, for which the value of each network element will be retrieved. If the value is time dependent, you can specify the time of day using the time_of_day parameter. For a single attribute, you can use a string instead of a list of strings. | String |
time_of_day | The time of day that time-dependent attribute values for this network element will be retrieved. When no time of day value is passed, the time-neutral value will be returned. | DateTime |
eids [eids,...] | A list of EID values to include in the cursor. This allows you to return only a subset of all network elements. If no value is passed for this parameter, all network elements are returned. The eids and area_of_interest parameters cannot be used simultaneously. | Integer |
travel_mode | The travel mode to apply when requesting junction properties and attribute values. The travel mode settings may impact the returned property and attribute values, particularly if the travel mode uses nondefault values for any attribute parameters. When no travel mode is specified, all values requested from attribute_names use their default attribute parameter values, and the ISRESTRICTED, COST, TIME, and DISTANCE properties are not available. The travel mode should be specified as a TravelMode object. You can use one of the network's travel modes obtained using the NetworkDataset object's travelModes property or use a custom TravelMode object. | Object |
area_of_interest | The spatial filter to apply when requesting junction properties and attribute values. This allows you to return only the subset of junctions that intersect the specified area of interest. The parameter should be specified as an Extent object or a Polygon object. If an Extent object is used, all junctions intersecting the rectangular extent are returned. If a Polygon object is used, all junctions intersecting the polygon's shape are returned. The Polygon option can be used to filter junctions by country or state boundaries, for example. If a 3D polygon is used, all junctions intersecting the 2D projection of the polygon are returned. The eids and area_of_interest parameters cannot be used simultaneously. | Object |
数据类型 | 说明 |
Object | 用于迭代所返回交汇点的 NetworkDatasetJunctionCursor 对象。 每行均是一组该交汇点 junction_properties 和 attribute_names 参数中指定项目的值。 |
turns ({turn_properties}, {attribute_names}, {eids}, {travel_mode}, {area_of_interest})
参数 | 说明 | 数据类型 |
turn_properties [turn_properties,...] | A list of strings representing the network turn properties to retrieve. For a single property, you can use a string instead of a list of strings. The available properties include the following:
To request the ISRESTRICTED, COST, TIME, and DISTANCE properties, you must specify a value for the travel_mode parameter. | String |
attribute_names [attribute_names,...] | The list of network dataset attribute names, such as costs or restrictions, for which to retrieve the value for each network element. For a single attribute, you can use a string instead of a list of strings. | String |
eids [eids,...] | A list of EID values to include in the cursor. This allows you to return only a subset of all network elements. If no value is passed for this parameter, all network elements are returned. The eids and area_of_interest parameters cannot be used simultaneously. | Integer |
travel_mode | The travel mode to apply when requesting turn properties and attribute values. The travel mode settings may impact the returned property and attribute values, particularly if the travel mode uses nondefault values for any attribute parameters. When no travel mode is specified, all values requested from attribute_names use their default attribute parameter values, and the ISRESTRICTED, COST, TIME, and DISTANCE properties are not available. The travel mode should be specified as a TravelMode object. You can use one of the network's travel modes obtained using the NetworkDataset object's travelModes property or use a custom TravelMode object. | Object |
area_of_interest | The spatial filter to apply when requesting turn properties and attribute values. This allows you to return only the subset of turns that intersect the specified area of interest. The parameter should be specified as an Extent object or a Polygon object. If an Extent object is used, all turns intersecting the rectangular extent are returned. If a Polygon object is used, all turns intersecting the polygon's shape are returned. The Polygon option can be used to filter turns by country or state boundaries, for example. If a 3D polygon is used, all turns intersecting the 2D projection of the polygon are returned. The eids and area_of_interest parameters cannot be used simultaneously. | Object |
数据类型 | 说明 |
Object | 用于迭代所返回转弯的 NetworkDatasetTurnCursor 对象。 每行均是一组该转弯 turn_properties 和 attribute_names 参数中指定项目的值。 |
updateNetworkDatasetSchema ({custom_evaluators}, {custom_directions})
参数 | 说明 | 数据类型 |
custom_evaluators | A dictionary that describes the custom evaluators that will be associated with the network dataset. Learn more about custom evaluators The dictionary keys are the network attribute names that the custom evaluator will be applied to. The values are a dictionary with a class key and an optional sourceNames key. The class key value describes how to import the custom evaluator class from the active ArcGIS Pro Python environment's site-packages directory using a dot notation to specify the package, module, and class. The sourceNames key value is a list of network source names specifying the sources the custom evaluator applies to. If this key is not included in the dictionary, the custom evaluator will apply to all sources. This code snippet shows a dictionary with the correct structure to update the network dataset's Minutes attribute with a custom evaluator whose code is defined in a class named CostCustomizer in a Python file named custom_eval.py in a folder Python na_customization in the Python environment's site-packages directory. Only include a given network attribute in the dictionary once. You can only associate one custom evaluator with a given attribute. To remove a reference to existing custom evaluators from the network dataset schema, use a value of None when calling this method.
警告:Positional arguments are not supported with this method. To associate a custom evaluator with the network, you must use the named argument custom_evaluators when calling this method. | Dictionary |
custom_directions | A dictionary that describes the directions customization classes that will be associated with the network dataset. Learn more about custom directions The dictionary must have a key named class. The value describes how to import the custom evaluator class from the active ArcGIS Pro Python environment's site-packages directory using a dot notation to specify the package, module, and class. This code snippet shows a dictionary with the correct structure to update the network dataset schema with a custom directions class named DirectionsCustomizer in a Python file named custom_directions.py in a folder named na_customization in the Python environment's site-packages directory. To remove a reference to existing custom directions classes from the network dataset schema, use a value of None when calling this method.
警告:Positional arguments are not supported with this method. To associate a custom directions class with the network, you must use the named argument custom_directions when calling this method. | Dictionary |
代码示例
打印网络中每个边的行驶时间不仅限于汽车。
# Print the travel time for each edge in the network that is not restricted to automobiles
import datetime
import arcpy
arcpy.CheckOutExtension("network")
nds_path = r"E:\TutorialData\Network Analyst\Tutorial\SanDiego.gdb\Transportation\Streets_ND"
# Initialize the NetworkDataset object
nds = arcpy.nax.NetworkDataset(nds_path)
# Print network dataset build information
print(f"Network dataset is built: {nds.isBuilt}")
print(f"Most recent build time: {nds.buildTimestamp}")
# Iterate through all the edges in the network and get the TravelTime cost attribute
# value for a specific time of day. Only print the value if the edge is not restricted
# to automobiles
edges = nds.edges("EID", ["TravelTime", "Driving an Automobile"], datetime.datetime(2019, 4, 19, 8, 0, 0))
for edge in edges:
if not edge[2]:
print(f"TravelTime for EID {edge[0]}: {edge[1]}")
检索参与转弯的所有边上所有交汇点的 ObjectID 值。
# Retrieve the ObjectIDs of all junctions for all edges that participate in turns
import arcpy
arcpy.CheckOutExtension("network")
nds_path = r"E:\TutorialData\Network Analyst\Tutorial\SanDiego.gdb\Transportation\Streets_ND"
# Initialize the NetworkDataset object
nds = arcpy.nax.NetworkDataset(nds_path)
# Iterate through all turns in the network and get the edges that participate
turns = nds.turns(["SOURCEOID", "EDGEEIDS"])
for turn in turns:
# For the edges in the turn, get the from and to junctions
edges = nds.edges(["SOURCEOID", "FROMJUNCTION", "TOJUNCTION"], eids=turn[1])
for edge in edges:
# For the from and to junction, get the SOURCEOID
junctions = nds.junctions("SOURCEOID", eids=[edge[1], edge[2]])
junctionOIDs = [j[0] for j in junctions]
对于 Walking Time 出行模式,检索所有网络边的成本和受限状态。
# Retrieve the cost and restricted status for all network edges for the Walking Time travel mode
import arcpy
arcpy.CheckOutExtension("network")
nds_path = r"E:\TutorialData\Network Analyst\Tutorial\SanDiego.gdb\Transportation\Streets_ND"
# Initialize the NetworkDataset object
nds = arcpy.nax.NetworkDataset(nds_path)
# Iterate through all the edges in the network and print the cost to traverse it with the Walking Time travel mode and
# whether or not the edge is restricted.
for edge in nds.edges(["EID", "COST", "ISRESTRICTED"], travel_mode=nds.travelModes["Walking Time"]):
print(f"EID {edge[0]} -- COST: {edge[1]}; RESTRICTED: {edge[2]}")
检索指定范围内的交汇点的 ObjectID 值。
# Retrieve the ObjectID values for junctions within a specified extent
import arcpy
arcpy.CheckOutExtension("network")
nds_path = r"E:\TutorialData\Network Analyst\Tutorial\SanDiego.gdb\Transportation\Streets_ND"
extent_fc = r"E:\TutorialData\Network Analyst\Tutorial\SanDiego.gdb\Analysis\AnalysisExtent"
# Initialize the NetworkDataset object
nds = arcpy.nax.NetworkDataset(nds_path)
# Get the extent from the feature class
extent = arcpy.Describe(extent_fc).extent
# Retrieve the junctions that fall within the designated extent
for junction in nds.junctions(["SOURCEOID"], area_of_interest=extent):
print(junction)
检索指定地区内的交汇点的 ObjectID 值。
# Retrieve the ObjectID values for junctions within specified territories
import arcpy
arcpy.CheckOutExtension("network")
nds_path = r"E:\TutorialData\Network Analyst\Tutorial\SanDiego.gdb\Transportation\Streets_ND"
territories = r"E:\TutorialData\Network Analyst\Tutorial\SanDiego.gdb\Analysis\Territories"
# Initialize the NetworkDataset object
nds = arcpy.nax.NetworkDataset(nds_path)
# Iterate through the polygons in the Territories feature class and retrieve
# the junctions that fall within each territory's boundary.
for row in arcpy.da.SearchCursor(territories, ["Name", "SHAPE@"]):
print(f"Junctions in territory {row[0]}:")
for junction in nds.junctions(["SOURCEOID"], area_of_interest=row[1]):
print(junction[0])