NetworkDataset
汇总
提供网络数据集属性的访问权限。 您可以使用此类检索网络数据集边、交汇点和转弯的属性和属性值,以及网络数据集的其他属性。
语法
NetworkDataset(in_network)
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
in_network |
要检索其属性的网络数据集。可以使用网络数据集的目录路径、网络数据集图层对象或网络数据集图层的字符串名称来指定参数。 |
String |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
buildTimestamp (只读) |
最近构建的网络数据集的日期和时间。 |
DateTime |
|
customEvaluators (读取和写入) |
用于在求解操作中自定义边、交汇点和转弯的网络属性值的 Python 类列表。 必须将属性指定为从 自定义赋值器类不能使用此属性与网络数据集永久关联。 关联是临时的,仅适用于设置了此属性的同一脚本中的求解操作。 若要永久保留与自定义赋值器类的关联,请使用 |
Object |
|
directionsCustomizer (读取和写入) |
在求解操作中使用网络数据集时,用于对返回的方向行进策略文本进行自定义的 Python 类。 必须将属性指定为从 自定义方向类不能使用此属性与网络数据集永久关联。 关联是临时的,仅适用于设置了此属性的同一脚本中的求解操作。 若要永久保留与自定义方向类的关联,请使用 |
Object |
|
edgeCount (只读) |
网络中的边数。 |
Integer |
|
isBuilt (只读) |
指定是否构建网络数据集。 值 |
Boolean |
|
junctionCount (只读) |
网络中的交汇点数。 |
Integer |
|
travelModes (只读) |
返回适用于网络数据集的出行模式对象的字典。 字典关键字是出行模式的名称,字典值是出行模式对象。 此属性与 |
Dictionary |
|
turnCount (只读) |
网络中的转弯数。 |
Integer |
方法
checkIntersectingFeatures(feature_layer, cutoff)
返回一个布尔值,指示指定的网络数据集内与指定的要素图层中的要素相交的边源要素的数量是小于还是等于指定中断。对于可作为线障碍或面障碍加载到网络分析问题的要素,该选项有助于限制其数量。
此方法与 CheckIntersectingFeatures 函数类似。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
feature_layer |
|
Layer |
|
cutoff |
相交要素的最大数量。 |
Integer |
返回值
| 数据类型 | 说明 |
|---|---|
|
Boolean |
如果相交要素的数量小于或等于 |
describe()
将返回包含网络数据集其他属性的 Describe 对象。这等同于使用网络数据集上的 arcpy.Describe 。
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
网络数据集 |
edges({edge_properties[edge_properties,...]}, {attribute_names[attribute_names,...]}, {time_of_day}, {eids[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 |
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 |
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 The |
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 The travel mode should be specified as a |
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 The |
Object |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
用于迭代所返回的边的 |
getDataSourceFromSourceID(source_id)
返回由给定源 ID 标识的网络数据集源要素类的目录路径。
提示:
此方法瞬时生效,因为它将读取已缓存值。 代码可以重复调用此方法,并尽可能降低性能影响。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
source_id |
The network source ID for which the corresponding source feature class's catalog path will be retrieved. |
Integer |
返回值
| 数据类型 | 说明 |
|---|---|
|
String |
网络数据集源要素类的目录路径。 |
getLiveTrafficStatus(wait_for_update)
对于配置了 OpenLR 实时流量 的网络数据集, getLiveTrafficStatus 读取本地流量缓存并返回包含关键状态指示器的字典。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
wait_for_update |
Specifies whether the function will wait for any ongoing cache update to complete before retuning the status.
(默认值为 False) |
Boolean |
返回值
| 数据类型 | 说明 |
|---|---|
|
Dictionary |
包含有关实时流量源及其缓存的关键状态指示器的字典。 字典中的关键字如下:
示例输出字典
|
junctions({junction_properties[junction_properties,...]}, {attribute_names[attribute_names,...]}, {time_of_day}, {eids[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 |
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 |
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 The |
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 The travel mode should be specified as a |
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 The |
Object |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
用于迭代所返回交汇点的 |
turns({turn_properties[turn_properties,...]}, {attribute_names[attribute_names,...]}, {eids[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 |
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 The |
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 The travel mode should be specified as a |
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 The |
Object |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
用于迭代所返回转弯的 |
updateNetworkDatasetSchema({custom_evaluators}, {custom_directions}, {openlr_traffic_service_id}, {openlr_traffic_feed_ids})
更新网络数据集,以将自定义赋值器或方向 Python 类与网络相关联或设置 OpenLR 实时流量 服务 ID 或源 ID。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
custom_evaluators (可选) |
A dictionary that describes the custom evaluators that will be associated with the network dataset. The dictionary keys are the network attribute names that the custom evaluator will be applied to. The values are a dictionary with a This code snippet shows a dictionary with the correct structure to update the network dataset's
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
注意:Positional arguments are not supported with this method. To associate a custom evaluator with the network, you must use the named argument |
Dictionary |
|
custom_directions (可选) |
A dictionary that describes the directions customization classes that will be associated with the network dataset. The dictionary must have a This code snippet shows a dictionary with the correct structure to update the network dataset schema with a custom directions class named
To remove a reference to existing custom directions classes from the network dataset schema, use a value of
注意:Positional arguments are not supported with this method. To associate a custom directions class with the network, you must use the named argument |
Dictionary |
|
openlr_traffic_service_id (可选) |
Specifies an ID that represents the OpenLR live traffic service that the network will use. Valid values are as follows:
|
String |
|
openlr_traffic_feed_ids (可选) |
Specifies one or more IDs that represents the OpenLR live traffic feed IDs that the network will use. The schema can only have the traffic service ID or the traffic feed IDs set. Setting one will clear the other from the schema. Setting both in a single call with raise an exception. Valid values are as follows:
|
String |
updateTrafficCache({timeout_seconds})
对于配置了 OpenLR 实时流量 的网络数据集, updateTrafficCache 使用最新的速度数据、道路封闭情况和相关元数据刷新本地流量缓存。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
timeout_seconds (可选) |
The maximum duration in seconds the function can run. If this time limit is exceeded, the function will automatically terminate. If no value is specified, the timeout duration will be the number of seconds specified by the |
Long |
代码示例
打印网络中每个边的行驶时间不仅限于汽车。
# Print the travel time for each edge in the network that is not restricted to automobiles
import datetime
import arcpy
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
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
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
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
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])