arcpy.Polyline doesn't appear to work

277
1
11-22-2011 09:08 AM
MarkRabenhorst1
New Contributor
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.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?
Tags (2)
0 Kudos
1 Reply
MarkRabenhorst1
New Contributor
More data to look at... using this as the array of points:

point1 = arcpy.Point(-105.523164394,40.520164394)
    arcPointArray.add(point1)
    point2 = arcpy.Point(-105.520162394,40.520164394)
    arcPointArray.add(point2)
    point3 = arcpy.Point(-105.520164394,40.520164394)
    arcPointArray.add(point3)
    point4 = arcpy.Point(-105.520764394,40.520164394)
    arcPointArray.add(point4)
    point5 = arcpy.Point(-105.524164394,40.520164394)
    arcPointArray.add(point5)
    point6 = arcpy.Point(-105.520134394,40.520164394)
    arcPointArray.add(point6)


I get this result:

points in line: 6
Create polyline
point count: 5
points after import: 5
Point: x -105.523164394 y 40.520164394
Point: x -105.520163394 y 40.520164394
Point: x -105.520764394 y 40.520164394
Point: x -105.524164394 y 40.520164394
Point: x -105.520134394 y 40.520164394

One point is missing, and it is point 3: -105.520164394, 40.520164394

Why????
0 Kudos