NetworkDataset
Summary
Provides access to the properties of a network dataset. You can use this class to retrieve the properties and attribute values for network dataset edges, junctions, and turns, as well as other properties of the network dataset.
Syntax
NetworkDataset(in_network)
| Name | Explanation | Data type |
|---|---|---|
|
in_network |
The network dataset whose properties you want to retrieve. The argument can be specified using the catalog path to the network dataset, a network dataset layer object, or the string name of the network dataset layer. |
String |
Properties
| Name | Explanation | Data type |
|---|---|---|
|
buildTimestamp (Read only) |
The date and time the network dataset was most recently built. |
DateTime |
|
customEvaluators (Read and Write) |
A list of Python classes that customize the network attribute values for edges, junctions, and turns during a solve operation. The property must be specified as a list of instances of user-defined classes inheriting from the Custom evaluator classes cannot be permanently associated with the network dataset using this property. The association is temporary and applies only to solve operations within the same script where this property is set. To permanently persist an association with a custom evaluator class, use the |
Object |
|
directionsCustomizer (Read and Write) |
A Python class that customizes the directions maneuver text returned when the network dataset is used in a solve operation. The property must be specified as an instance of a user-defined class inheriting from the Custom directions classes cannot be permanently associated with the network dataset using this property. The association is temporary and applies only to solve operations within the same script where this property is set. To permanently persist an association with a custom directions class, use the |
Object |
|
edgeCount (Read only) |
The number of edges in the network. |
Integer |
|
isBuilt (Read only) |
Specifies whether the network dataset is built. A value of |
Boolean |
|
junctionCount (Read only) |
The number of junctions in the network. |
Integer |
|
travelModes (Read only) |
Returns a dictionary of travel mode objects that are available on the network dataset. The dictionary keys are the names of the travel modes, and the dictionary values are the |
Dictionary |
|
turnCount (Read only) |
The number of turns in the network. |
Integer |
Methods
checkIntersectingFeatures(feature_layer, cutoff)
Returns a Boolean value indicating whether the number of edge source features from the specified network dataset that are intersected by the features within the specified feature layer is less than or equal to the specified cutoff. This is useful for restricting the number of features that can be loaded as line or polygon barriers into a network analysis problem.
This method is similar to the CheckIntersectingFeatures function.
| Name | Explanation | Data type |
|---|---|---|
|
feature_layer |
A |
Layer |
|
cutoff |
The maximum number of intersecting features. |
Integer |
Return value
| Data type | Explanation |
|---|---|
|
Boolean |
Returns |
describe()
Returns a Describe object that contains additional properties of the network dataset. This is equivalent to using arcpy.Describe on the network dataset.
Return value
| Data type | Explanation |
|---|---|
|
Object |
A network dataset |
edges({edge_properties[edge_properties,...]}, {attribute_names[attribute_names,...]}, {time_of_day}, {eids[eids,...]}, {travel_mode}, {area_of_interest})
Returns an iterator of network dataset edge elements you can use to access the value of specific edge properties and network attributes at the time of day specified.
| Name | Explanation | Data type |
|---|---|---|
|
edge_properties[edge_properties,...] (Optional) |
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,...] (Optional) |
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 (Optional) |
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,...] (Optional) |
A list of The |
Integer |
|
travel_mode (Optional) |
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 (Optional) |
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 |
Return value
| Data type | Explanation |
|---|---|
|
Object |
A |
getDataSourceFromSourceID(source_id)
Returns the catalog path of the network dataset source feature class identified by the given source ID.
Tip:
This method is effectively instantaneous because it reads a cached value. Your code can call this method repeatedly with minimal performance impact.
| Name | Explanation | Data type |
|---|---|---|
|
source_id |
The network source ID for which the corresponding source feature class's catalog path will be retrieved. |
Integer |
Return value
| Data type | Explanation |
|---|---|
|
String |
The catalog path of the network dataset source feature class. |
getLiveTrafficStatus(wait_for_update)
For a network dataset configured with OpenLR live traffic, getLiveTrafficStatus reads the local traffic cache and returns a dictionary containing key status indicators.
| Name | Explanation | Data type |
|---|---|---|
|
wait_for_update |
Specifies whether the function will wait for any ongoing cache update to complete before retuning the status.
The default value is False. |
Boolean |
Return value
| Data type | Explanation |
|---|---|
|
Dictionary |
A dictionary containing key status indicators about the live traffic feed and its cache. The dictionary keys are as follows:
The
Example output dictionary
|
junctions({junction_properties[junction_properties,...]}, {attribute_names[attribute_names,...]}, {time_of_day}, {eids[eids,...]}, {travel_mode}, {area_of_interest})
Returns an iterator of network dataset junction elements that you can use to access the value of specific junction properties and network attributes at the time of day specified.
| Name | Explanation | Data type |
|---|---|---|
|
junction_properties[junction_properties,...] (Optional) |
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,...] (Optional) |
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 (Optional) |
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,...] (Optional) |
A list of The |
Integer |
|
travel_mode (Optional) |
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 (Optional) |
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 |
Return value
| Data type | Explanation |
|---|---|
|
Object |
A |
turns({turn_properties[turn_properties,...]}, {attribute_names[attribute_names,...]}, {eids[eids,...]}, {travel_mode}, {area_of_interest})
Returns an iterator of network dataset turn elements you can use to access the value of specific turn properties and network attributes.
| Name | Explanation | Data type |
|---|---|---|
|
turn_properties[turn_properties,...] (Optional) |
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,...] (Optional) |
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,...] (Optional) |
A list of The |
Integer |
|
travel_mode (Optional) |
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 (Optional) |
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 |
Return value
| Data type | Explanation |
|---|---|
|
Object |
A |
updateNetworkDatasetSchema({custom_evaluators}, {custom_directions}, {openlr_traffic_service_id}, {openlr_traffic_feed_ids}, {travel_modes})
Updates the network dataset to associate a custom evaluator or directions Python class with the network or set the OpenLR live traffic service ID or feed IDs.
| Name | Explanation | Data type |
|---|---|---|
|
custom_evaluators (Optional) |
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
Caution: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 (Optional) |
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
Caution: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 (Optional) |
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 (Optional) |
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 |
|
travel_modes (Optional) |
Allows you to replace the network dataset's travel modes with the travel modes defined in the dictionary passed to the parameter. The dictionary keys are the travel mode names, and the values are
The dictionary has the same structure as the dictionary returned by the The first travel mode in the dictionary will be set as the network dataset's default travel mode. Passing an empty dictionary deletes all travel modes on the network. The method will error if the travel mode properties don't match the available attributes and parameters on the network. |
Dictionary |
updateTrafficCache({timeout_seconds})
For a network dataset configured with OpenLR live traffic, updateTrafficCache refreshes the local traffic cache with the latest speed data, road closures, and related metadata.
| Name | Explanation | Data type |
|---|---|---|
|
timeout_seconds (Optional) |
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 |
Code sample
Print the travel time for each edge in the network that is not restricted to automobiles.
# 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]}")
Retrieve the ObjectID values of all junctions for all edges that participate in turns.
# 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]
Retrieve the cost and restricted status for all network edges for the Walking Time travel mode.
# 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]}")
Retrieve the ObjectID values for junctions within a specified extent.
# 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)
Retrieve the ObjectID values for junctions within specified territories.
# 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])
Add a new travel mode to the network dataset. Copy the Walking Time travel mode and increase the walk speed.
# Add a travel mode to a network dataset
import arcpy
nds_path = r"C:\Data\NorthAmerica.gdb\Routing\Routing_ND"
# Initialize the NetworkDataset object
nds = arcpy.nax.NetworkDataset(nds_path)
# Get a dictionary representing the network's current travel modes
travel_modes = nds.travelModes
# Create a new travel mode based on the existing "Walking Time" travel mode
fast_walk_tm = arcpy.nax.TravelMode(travel_modes["Walking Time"])
fast_walk_tm.name = "Fast Walking Time"
# Increase the walking speed
attr_params = fast_walk_tm.attributeParameters
attr_params[('WalkTime', 'Walking Speed (km/h)')] = 6
fast_walk_tm.attributeParameters = attr_params
# Add the new travel mode to the travel mode dictionary
travel_modes["Fast Walking Time"] = fast_walk_tm
# Replace the network's travel modes with the updated dictionary
nds.updateNetworkDatasetSchema(travel_modes=travel_modes)