摘要
可以提供网络数据集属性的只读访问权限。 您可以使用此类检索网络数据集边、交汇点和转弯的属性和属性值,以及网络数据集的其他属性。
语法
NetworkDataset (in_network)
参数 | 说明 | 数据类型 |
in_network | 要检索其属性的网络数据集。可以使用网络数据集的目录路径、网络数据集图层对象或网络数据集图层的字符串名称来指定参数。 | String |
属性
属性 | 说明 | 数据类型 |
buildTimestamp (只读) | 最近构建的网络数据集的日期和时间。 | DateTime |
isBuilt (只读) | 指示是否构建网络数据集。False 值表示需要重建网络数据集以合并更改。 | Boolean |
travelModes (只读) | 返回适用于网络数据集的出行模式对象的字典。字典关键字是出行模式的名称,字典值是出行模式对象。此属性与 GetTravelModes 函数所返回的输出相同。 | Dictionary |
方法概述
方法 | 说明 |
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}) | 返回网络数据集转弯元素的迭代器,您可用其访问特定转弯属性和网络属性的值。 |
方法
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 参数中指定项目的值。 |
代码示例
打印网络中每个边的行驶时间不仅限于汽车。
# 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])