I want to create lines based on two points:
1st line: point number 1 from pointFc, point number 1 from centFc
2nd line: point number 2 from pointFc, point number 2 from centFc
and so on
Where did I make mistake?
start_cursor = arcpy.SearchCursor(pointFc)
end_cursor = arcpy.SearchCursor(centFc)
desc = arcpy.Describe(pointFc)
desc2 = arcpy.Describe(centFc)
shapefieldname = desc.ShapeFieldName
OID_start = desc.OIDFieldName
OID_end = desc2.OIDFieldName
point = arcpy.Point()
array = arcpy.Array()
featureList = []
cursor = arcpy.InsertCursor(lineFc)
feat = cursor.newRow()
for start in start_cursor:
startFeature = start.getValue(shapefieldname)
start_id = start.getValue(OID_start)
pnt1 = startFeature.getPart()
for end in end_cursor:
end_id = end.getValue(OID_end)
endFeature = end.getValue(shapefieldname)
pnt2 = endFeature.getPart()
if start_id == end_id:
point.X = pnt1.X
point.Y = pnt1.Y
array.add(point)
point.X = pnt2.X
point.Y = pnt2.Y
array.add(point)
polyline = arcpy.Polyline(array)
array.removeAll()
featureList.append(polyline)
feat.shape = polyline
cursor.insertRow(feat)
del feat, cursor, end_cursor, start_cursor
Best Answer
Here's how to do it using arcpy.da cursors (ArcGIS 10.1+):
OR using existing tools (example below has OID values moved into "ID" field. OIDs will be recalculated when merged):