I'm relatively new to arcpy and python.
I have a script that creates triangular polygons given two point shapefiles of centroid points and vertexes around them. I need to run this over ~170k points, which would take more than a week at my available processing power, especially if Murphy's Law strikes during the script execution. I haven't had much luck digging through the Arcpy docs and coming up with anything that could give me the same results in less time.
Can anyone point me in the direction of a different tool chain for this if they can think of one?
Or notice anything in the code that would hamper performance?
with centroidCursor as cecursor:
for record in cecursor:
whereClause = "IN_FID = " + str(record[0])
selection = arcpy.SelectLayerByAttribute_management(nearTableView, "NEW_SELECTION", whereClause) # get the all the records that have that centroid ID from the near table
with arcpy.da.SearchCursor(selection, "NEAR_FID") as selcursor: # then append the vertex IDs to a list
tempList = [row[0]] # create temporary list
for selrow in selcursor:
tempList.append(selrow[0]) # iterate though rows appending vertex IDs to list
idNum = record[0]
whereClause = "OBJECTID = {0} OR OBJECTID = {1} OR OBJECTID = {2}".format(tempList[0],tempList[1],tempList[2])
selected = arcpy.SelectLayerByAttribute_management(cornerpoints, "NEW_SELECTION", whereClause) # select the vertexes from the list
lines = arcpy.PointsToLine_management(selected, "in_memory", Close_Line="CLOSE") # convert points to a temporary lines
poly = arcpy.FeatureToPolygon_management(lines, workspace + "/mesh_polys/polygons{0}".format(idNum)) # then convert lines to polygons stored in a dataset
I'm going to first try going straight from points to polygons with the Geometry class. From the discussion in the comments the follow up will be one of two methods:
A - Using a layer definition query inside the nested searchCursors (I'm unfamiliar with this and it's throwing a bunch of different errors as I'm working with it after FelixIP pointed me in it's direction).
B - creating a custom table with some kind of relevant information tied to the cursor_ID (vertex geometry, perhaps?).
I now understand what the definition queries do and they are absolutely faster.
whereClause = "OBJECTID IN ({0} , {1} , {2})".format(tempList[0],tempList[1],tempList[2])
cornerpoints.definitionQuery = whereClause
selection = cornerpoints
lines = arcpy.PointsToLine_management(selection, workspace + "/mesh_lines/line{0}".format(row[0]), Close_Line="CLOSE")# convert points to a temporary lines
However, I'm now getting this error when I try to run the script:
ExecuteError: IOError: "GPL0" does not exist
There's very little about what can cause this error that I can find. Anyone know what I'm missing?