NetworkDataset

Synthèse

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.

Syntaxe

NetworkDataset (in_network)
ParamètreExplicationType de données
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

Propriétés

PropriétéExplicationType de données
buildTimestamp
(Lecture seule)

The date and time the network dataset was most recently built.

DateTime
customEvaluators
(Lecture et écriture)

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 arcpy.nax.AttributeEvaluator class.

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 updateNetworkDatasetSchema method.

Learn more about custom evaluators

Object
directionsCustomizer
(Lecture et écriture)

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 arcpy.nax.DirectionsCustomizer class.

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 updateNetworkDatasetSchema method.

Learn more about custom directions

Object
isBuilt
(Lecture seule)

Specifies whether the network dataset is built. A value of False indicates that the network dataset needs to be rebuilt to incorporate changes.

Boolean
travelModes
(Lecture seule)

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 travel mode objects. This property returns the same output as the GetTravelModes function.

Dictionary

Vue d’ensemble des méthodes

MéthodeExplication
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.

describe ()

Returns a Describe object that contains additional properties of the network dataset. This is equivalent to using arcpy.Describe on the network dataset.

edges ({edge_properties}, {attribute_names}, {time_of_day}, {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.

getDataSourceFromSourceID (source_id)

Returns the catalog path of the network dataset source feature class identified by the given source ID.

Conseil :

This method is effectively instantaneous because it reads a cached value. Your code can call this method repeatedly with minimal performance impact.

junctions ({junction_properties}, {attribute_names}, {time_of_day}, {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.

turns ({turn_properties}, {attribute_names}, {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.

updateNetworkDatasetSchema ({custom_evaluators}, {custom_directions})

Updates the network dataset to associate a custom evaluator or directions Python class with the network.

Méthodes

checkIntersectingFeatures (feature_layer, cutoff)
ParamètreExplicationType de données
feature_layer

A Layer object containing the features that intersect the network edge sources. Any selection set or definition query present on the layer object is honored and can be used to specify only a subset of features.

Layer
cutoff

The maximum number of intersecting features.

Integer
Valeur renvoyée
Type de donnéesExplication
Boolean

Returns True if the number of intersecting features is less than or equal to the cutoff value. Returns False if the number of intersecting features exceeds the cutoff value.

describe ()
Valeur renvoyée
Type de donnéesExplication
Object

A network dataset Describe object.

edges ({edge_properties}, {attribute_names}, {time_of_day}, {eids}, {travel_mode}, {area_of_interest})
ParamètreExplicationType de données
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:

  • EIDThe ID of the edge.
  • SOURCEID The ID of the source feature class of the edge.
  • SOURCEOID The ObjectID of the feature within the source feature class from which this network edge is derived.
  • FROMPOSITION The distance along the source feature where this network edge starts. A network edge can represent a partial feature in the source feature class.
  • TOPOSITION The distance along the source feature where this network edge ends.
  • DIRECTION A Boolean value indicating whether the edge's direction is along the direction of digitization of the source feature. A value of True means that the edge's direction is along the direction of digitization, and a value of False means that the edge's direction is against the direction of digitization.
  • FROMJUNCTION The EID of the junction feature at the beginning of the edge.
  • TOJUNCTION The EID of the junction feature at the end of the edge.
  • ISRESTRICTEDA Boolean value indicating whether the edge is restricted for the specified travel mode.
  • COSTThe cost to traverse the edge for the specified travel mode.
  • TIMEThe time cost to traverse the edge for the specified travel mode.
  • DISTANCEThe distance cost incurred by traversing the edge for the specified travel mode.

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
Valeur renvoyée
Type de donnéesExplication
Object

A NetworkDatasetEdgeCursor object that can be used to iterate over the returned edges. Each row is a tuple with the values of the items specified in the edge_properties and attribute_names parameters for that edge.

getDataSourceFromSourceID (source_id)
ParamètreExplicationType de données
source_id

The network source ID for which the corresponding source feature class's catalog path will be retrieved.

Integer
Valeur renvoyée
Type de donnéesExplication
String

The catalog path of the network dataset source feature class.

junctions ({junction_properties}, {attribute_names}, {time_of_day}, {eids}, {travel_mode}, {area_of_interest})
ParamètreExplicationType de données
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:

  • EIDThe ID of the junction.
  • SOURCEID The ID of the source feature class of the junction.
  • SOURCEOID The ObjectID of the feature within the source feature class from which this network junction is derived.
  • ISRESTRICTEDA Boolean value indicating whether the junction is restricted for the specified travel mode.
  • COSTThe cost to traverse the junction for the specified travel mode.
  • TIMEThe time cost to traverse the junction for the specified travel mode.
  • DISTANCEThe distance cost incurred by traversing the junction for the specified travel mode.

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
Valeur renvoyée
Type de donnéesExplication
Object

A NetworkDatasetJunctionCursor object that can be used to iterate over the returned junctions. Each row is a tuple with the values of the items specified in the junction_properties and attribute_names parameters for that junction.

turns ({turn_properties}, {attribute_names}, {eids}, {travel_mode}, {area_of_interest})
ParamètreExplicationType de données
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:

  • EIDThe ID of the turn.
  • SOURCEID The ID of the source feature class of the turn.
  • SOURCEOID The ObjectID of the feature within the source feature class from which this network turn is derived.
  • EDGEEIDS An ordered list of EID values of network edges that participate in this turn.
  • ISRESTRICTEDA Boolean value indicating whether the turn is restricted for the specified travel mode.
  • COSTThe cost to traverse the turn for the specified travel mode.
  • TIMEThe time cost to traverse the turn for the specified travel mode.
  • DISTANCEThe distance cost incurred by traversing the turn for the specified travel mode.

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
Valeur renvoyée
Type de donnéesExplication
Object

A NetworkDatasetTurnCursor object that can be used to iterate over the returned turns. Each row is a tuple with the values of the items specified in the turn_properties and attribute_names parameters for that turn.

updateNetworkDatasetSchema ({custom_evaluators}, {custom_directions})
ParamètreExplicationType de données
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.

ce_description = {
    "Minutes": {
        "class": "na_customization.custom_eval.CostCustomizer",
        "sourceNames": ["Streets"]
    }
}
nd.updateNetworkDatasetSchema(custom_evaluators=ce_description)

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.

nd.updateNetworkDatasetSchema(custom_evaluators=None)

Attention :

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.

cd_description = {"class": "na_customization.custom_directions.DirectionsCustomizer"}
nd.updateNetworkDatasetSchema(custom_directions=cd_description)

To remove a reference to existing custom directions classes from the network dataset schema, use a value of None when calling this method.

nd.updateNetworkDatasetSchema(custom_directions=None)

Attention :

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

Exemple de code

NetworkDataset example 1

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
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]}")
NetworkDataset example 2

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
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]
NetworkDataset example 3

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
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]}")
NetworkDataset example 4

Retrieve the ObjectID values for junctions within a specified extent.

# 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)
NetworkDataset example 5

Retrieve the ObjectID values for junctions within specified territories.

# 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])