Is it possible to create a network dataset with ArcPy to be used with the network assistant?

In the documentation I found the Build Network and Dissolve Network functions, but it looks like both require an already existing network dataset as input parameter.

In this thread people say it is not possible with Python but with .NET. In this thread, somebody says it is possible to create geometric networks with arcpy in 10.1. Is it possible to use a geometric network with the network assistant?

In the documentation it says: Only point and line feature classes are supported as input. The feature classes cannot participate in another geometric network or other advanced geodatabase dataset such as a topology, network dataset, terrain, or fabric.

  • Which ArcGIS version and license level are you using? Your link says 10.1 and Standard or Advanced is needed.
    – PolyGeo
    May 6, 2013 at 10:29

2 Answers 2


You cannot create a network dataset with arcpy at this time. Your option is to use ArcObjects. There is a Street Data Processing toolbox that is built on .NET by Esri (the source code is provided), which you might modify to meet your business workflows. A GP tool which is part of the toolbox creates a network dataset with certain user-defined parameters, so this should work fine for you too.

Geometric networks and network datasets are not the same thing and you cannot create a network dataset from a geometric network in ArcGIS. The only option is to use ArcObjects at this time.

  • thanks for your answer. I go for now with the custom approach, but as soon as I can benefit more from the network analyst features I will try it. It's a pitty that it is not possible to create network datasets directly from Python.
    – rbuffat
    May 13, 2013 at 13:33

As I currently only need all shortest paths between two set of points, I ended up by calculating the shortest paths on my own with the Python binding of the igraph library. What I have is an input data set with points and a dataset with the street network as set of polylines with start node, end node and length. What I do is first find for each data point the nearest point on the road network. Then I create the graph from the road network. For each data point, I add two new edges to the graph. This is actually the biggest part of the code. Maybe there are more elegant and shorter versions. I know for each data point the id of the polyline nearest to it. For each such polyline I iterate over the segments and check if the nearest point of the data point is on the segment or the points between.

Created on 13.05.2013

Create graph from road network dataset and find shortest path  


import arcpy
import igraph
from collections import defaultdict

poi_layer = 1  # Layer with points of interests.
street_layer = 2  # Layer with streets as polylines. Start and end vertex ids in fields

# Find for every poi closest point on road entwork
arcpy.analysis.Near(poi_layer, street_layer, location="LOCATION")

# Set of ids of all polylines containing a nearest point
intersect_points = defaultdict(set)

with arcpy.da.SearchCursor(poi_layer, ("SHAPE@", "NEAR_FID", "NEAR_DIST", "NEAR_X", "NEAR_Y", "OBJECTID")) as cursor:
    for row in cursor:
        near_fid = row[1]
        near_dist = row[2]
        near_x = row[3]
        near_y = row[4]
        objectId = row[5]
        id = str(objectId)
del row
del cursor

# Create Road Network
vertices = set()
edges, weights = [], []

fields = ["FNODE_", "TNODE_", "SHAPE@", "LENGTH", "OBJECTID_1"]
with arcpy.da.SearchCursor(street_layer, fields) as cursor:
    for row in cursor:
        s = str(int(row[0]))  # Start node id
        t = str(int(row[1]))  # End node id
        line = row[2]  # Polyline object of road
        length = row[3]  # Road length
        lineid = row[4]  # Road id


        # Check if road near to some data points
        if lineid in intersect_points:

            # For each intersection point
            for ip in intersect_points[lineid]:

                ip_near_distance = ip[2]
                ip_source_id = ip[3]

                intersect_point = arcpy.Point(ip[0], ip[1])
                last_point = None
                found = False
                length_from = 0.0
                length_to = 0.0

                # Check for each line segment if it intersects
                for part in line:

                    for current_point in part:

                        current_point_pg = arcpy.PointGeometry(current_point)

                        # Check if intersection point is on line point
                        if current_point_pg.contains(intersect_point):
                            found = True
                            length_from += ip_near_distance
                            length_to = ip_near_distance

                        if last_point is not None:

                            # Create line segment
                            array = arcpy.Array()
                            last_point_pg = arcpy.PointGeometry(last_point)
                            segment = arcpy.Polyline(array)

                            # Check if intersection point is on line segment
                            if not found and segment.contains(intersect_point):
                                found = True
                                length_from += ip_near_distance + \
                                length_to = ip_near_distance + \
                                last_point = current_point

                            if found:
                                length_to += segment.length
                                length_from += segment.length

                        last_point = current_point
                if not found:
                    print "Int point not found!"

                # If interection point found road, add new node to
                # network


                    # Add edge from start node to data point
                    edges.append((s, ip_source_id))

                    # Add edge from data point to end node
                    edges.append((ip_source_id, t))

        # Add road to network
        e = (s, t)
        w = length


del row
del cursor

# Create road network graph
g = igraph.Graph()
for v in vertices:
for e in edges:
    g.add_edge(e[0], e[1])
g.es["weight"] = weights

# Find location points
sources =  # List of vertices ids
targets =  # List of vertices ids

# Find shortest paths
shortest_paths = g.shortest_paths(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.