mrabenhorst

arcpy.Polyline doesn't appear to work

Discussion created by mrabenhorst on Nov 22, 2011
Latest reply on Nov 22, 2011 by mrabenhorst
I am creating a tool that edits the coordinates of polylines in a selection based on a couple parameters. But I have encountered a scenario where the arcpy.Polyline class doesn't actually create the polyline (or rather, it picks and chooses what it wants). Here is my code:

arcPointArray = arcpy.Array()

i = 0
for row in rows:
    # Create the geometry object
    #
    partnum = 0
    shapeCoordsArray = allLines[i].allPoints

    arcPointArray.removeAll()

    for coord in shapeCoordsArray:
        newX = float(coord.X)
        newY = float(coord.Y)
        newPoint = arcpy.Point(newX, newY)
        arcPointArray.add(newPoint)

    arcpy.AddMessage("points in line: "+str(len(arcPointArray)))

    newLine = arcpy.Polyline(arcPointArray)
    row.setValue("shape",newLine)

    rows.updateRow(row)

    shapeCoordsArray = row.getValue("shape").getPart(0)

    # TESTING

    j = 0
    for point in shapeCoordsArray:
        j+=1

    arcpy.AddMessage("points after import: "+str(j))

    # TESTING

    i+=1


My output looks something like this:

points in line: 7
points after import: 4
points in line: 9
points after import: 2
points in line: 9
points after import: 2

Notice how the arcpy.Array of arcpy.Point objects I am sending arcpy.Polyline has more points than the actual polyline that is created? And this is reflected in the actual shapefile when I import it into ArcMap.

Any idea of what is going on?

Outcomes