I'm sort of newbie to arcpy and trying to create a polyline based on the some predefined points which are put within "network_ND_Junctions1.shp". The code I've written seems like this:

import arcpy





for route in route_list:
    for node in route:

    with arcpy.da.SearchCursor(nodes_file,['FID','SHAPE@XY']) as cursor1:
        for row in cursor1:
            if row[0]in dictionary.keys():

    myArray = arcpy.Array(dictionary.values())
    myline = arcpy.Polyline(myArray)
    with arcpy.da.InsertCursor("Routes.shp",['SHAPE@']) as cursor2:
        newRow =[myline]

print myArray.count #output=2
print myline.pointCount #output=0

As you can see in the output comments, arcpy.Array works properly and contains two points but it seems that there's not any point within myline variable. How can I solve this issue?

  • 1
    dont trust FIDs in a shapefile they are subject to change without notice but that has nothing to do with your code. It seems your dictionary contains lists with a length of 1, this won't make a polyline. Can you try skipping the dictionary, replace dictionary={} with nList = [] then in the SearchCursor loop if row[0] in route: nList.append(arcpy.Point...) then myArray = arcpy.Array(nList), see if that will produce an output. – Michael Stimson Dec 10 '17 at 23:27
  • 2
    Please always specify the exact software in use. Even though the arcpy.Polyline() constructor makes the spatial_reference optional, it's a crime to not provide the SpatialReference from the target feature class in the constructor (because the default XY tolerance is used, which might collapse all your vertices to a single point). Your debugging output isn't adequate to indicate what is happening -- In the future, try printing more information. – Vince Dec 11 '17 at 3:07

This may or may not be part of your problem but:


should be:

arcpy.env.overwriteOutput = True

because arcpy.env.overwriteOutput needs to be set to a Boolean rather than a string.

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.