I am trying to speed up some current code that I have for looping through lines, getting their segments and ultimately the vertex points in Python.
Can anyone recommend a faster method than what I currently have (perhaps using a map function or dictionary)?
My code is very slow, especially when dealing with large numbers of features.
sup_list = [row for row in arcpy.da.SearchCursor(sup_lyr, fields)]
# with arcpy.da.SearchCursor(sup_lyr, fields) as sup_cursor:
for sup_row in pbar(sup_list, total=result, ascii=True):
exp = str(tracking_field) + " = {0}".format(sup_row[3])
sup_sel = arcpy.SelectLayerByAttribute_management(sup_lyr, "NEW_SELECTION", exp)
inf_sel = arcpy.SelectLayerByLocation_management(inf_lyr, "WITHIN_A_DISTANCE_GEODESIC", sup_sel, "50 Meters"
, "NEW_SELECTION", "NOT_INVERT")
sup_vertexList = []
sup_proj_geom = sup_row[1].projectAs(calc_utm(sup_row[1].firstPoint))
for part in sup_proj_geom:
for pnt in part:
sup_vertexList.append([pnt.Y, pnt.X])
with arcpy.da.SearchCursor(inf_sel, fields) as inf_cursor:
for inf_row in inf_cursor:
inf_vertexList = []
inf_proj_geom = inf_row[1].projectAs(calc_utm(inf_row[1].firstPoint))
for part in inf_proj_geom:
for pnt in part:
inf_vertexList.append([pnt.Y, pnt.X])