I'm currently trying to take the 'Shifting Features' script from ArcPy Cafe and this SE response and apply it to a similar script that will one by one, through all the features in a feature class, copy the first feature to another feature class, then create a copy of that feature X times with a set interval and angle.
So with this I should be able to take, say a feature class containing two lines, and create 5 lines, 3 feet apart at a 45 degree angle in a new feature class.
I figured this should be easy by nesting cursors, one for searching the original FC, one for inserting rows in the new FC, but I apparently don't know much about cursors in general, or SearchCursor or InsertCursor in general. The InsertCursor command runs the correct number of times, and creates the correct number of features, but the features have no geometry.
Can anyone help me figure out what I might be doing wrong? Thanks!
import arcpy, math # all of these will eventually be made arguments fc = r"c:/geometry/polylines.shp" # source feature class fc2 = r"c:/geometry/polylines_shift.shp" # destination feature class c_shift=3 # desired overall offset (hypotenuse) no_features=5 # number of features to duplicate between offsets angle=45 # angle of offsets # given the angle and the hypotenuse, determine the x and y coordinate shift x_shift=c_shift * math.cos(angle) y_shift=c_shift * math.sin(angle) # I know this will copy the existing features from fc to fc2 #This will eventually be replaced with a command to create a blank feature class once I get the meat of the script fixed if arcpy.Exists(fc2): arcpy.Delete_management(fc2) arcpy.Copy_management(fc,fc2) i_cursor = arcpy.da.InsertCursor(fc2,("SHAPE@XY")) with arcpy.da.SearchCursor(fc, ["SHAPE@XY"]) as cursor: for row in cursor: for n_feat in xrange(1, no_features+1): i_cursor.insertRow([[row + (x_shift*n_feat or 0), row + (y_shift*n_feat or 0)]]) del row, cursor, i_cursor