Hi Joshua, yupp. The entire script is tool long I think, here are the relevant excerpts:
First I create empty lists (including one for lines), then I start a cursor to go through a points featureclass and find start and end points for a transect line I draw. Then I produce the line array object using those points.
- ##Step through each point in temp_inpt_lyr.
- arcpy.AddMessage("Stepping through each top of dam point and finding bottom of dam point and corresponding elevation...")
- bt_points, txt_data, lines = [], [], [] ##bottom points geometry, output data for csv table, and line geometry are stored in these lists.
- cursor = arcpy.da.SearchCursor(temp_inpt_lyr, ["START_X", "START_Y", "UNIT_VECTOR_X", "UNIT_VECTOR_Y", fid])
- for row in cursor:
- arcpy.AddMessage(row[4]) ##Print the dam id for current point.
- st_point = arcpy.Point(row[0], row[1]) ##starting point (START_X, START_Y).
- ed_point = arcpy.Point(linext*row[2]+row[0], linext*row[3]+row[1]) ##Point at end of line drawn from st_point to linext map units in the opposite direction of the line from the same point to the nearest polygon (of dam surface area) using unit vector.
- line_arr = arcpy.Array([st_point, ed_point]) ##Array object to contain the st_point and ed_point coordinates that define the transect line used to profile the dam and identify the bottom of dam.
I then do some other stuff that isn't relevant to the lines geometry (just a bunch of processing reading the geometry and using data from it).
Then I use vectors to find a new point, and more importantly for the problem I'm having, I copy create a line object that contains the line geometry and append that to the lines list. After this it goes into the code in my original post.
- magnitude = slp_profile[bod][0] ##Find magnitude for vector bod.
- bt_points.append([arcpy.Point(magnitude*row[2]+st_point.X, magnitude*row[3]+st_point.Y), row[4], elv_profile[bod][1]]) ##Store bottom of dam point geometry, DAMNO, and elevation in list bt_points.
- line = arcpy.Polyline(line_arr, temp_inpt_lyr_spref) ##Have to create line object anew, not sure why but line object loses information after being input into InterpolateShape tool.
- lines.append([line, row[4]]) ##Add lines to polyline geometry for output transect featureclass.
Code in my original post (plus a little extra setting up fields).
- ##Create output featureclass to be populated with transect lines moving away from dams in downstream direction
- arcpy.AddMessage("Writing output transect line featureclass")
- outln_m = arcpy.management.CreateFeatureclass("in_memory", "{}_Transect".format(outpt_name), "POLYLINE", spatial_reference = temp_inpt_lyr_spref)
- arcpy.management.AddField(outln_m, fid, "TEXT", field_length = 6)
-
- arcpy.AddMessage(lines)
- arcpy.AddMessage(len(lines)) #DEBUG#
- ##Populate output transect line featureclass
- workspace = r"in_memory"
- with arcpy.da.Editor(workspace) as edit:
- cursor = arcpy.da.InsertCursor(outln_m, ["SHAPE@", fid])
- for row in lines:
- arcpy.AddMessage(row) #DEBUG#
- cursor.insertRow(row)
- del cursor, row
- arcpy.AddMessage(arcpy.management.GetCount(outln_m)) #DEBUG#
Sorry, it's a lot of code.