This worked for me:
import arcpy, os, numpy
arcpy.env.overwriteOutput = True
def add_points_along_lines(feats, output, seconds_field):
'''Splits lines by a distance or percentage
Required:
feats -- input features
output -- output line feature class
seconds_field -- field with seconds values
'''
def _range(stop, step):
return [i for i in numpy.arange(0, stop+1, step)
if i > 0 and i <= stop]
# create fc's
path, name = os.path.split(output)
sm = 'SAME_AS_TEMPLATE'
output = arcpy.CreateFeatureclass_management(path, name, 'POINT',
feats, sm, sm, feats).getOutput(0)
# add 'PT_DIST' field
add_fields = ['LINE_POS', 'SEG_LENGTH']
for field in add_fields:
arcpy.AddField_management(output, field, 'DOUBLE')
# loop thru geom
fields = [f.name for f in arcpy.ListFields(feats) if not f.required]
fields.insert(0, 'SHAPE@')
sec_id = fields.index(seconds_field)
# Cursors
irows = arcpy.da.InsertCursor(output, fields + add_fields)
with arcpy.da.SearchCursor(feats, fields) as rows:
for row in rows:
length = row[0].length
seg_leng = length / row[sec_id]
irows.insertRow((row[0].firstPoint,) + row[1:] + (0,0))
# step through each distance
for i in _range(length, seg_leng):
pt = row[0].positionAlongLine(i)
irows.insertRow((pt,) + row[1:] + (i, seg_leng))
del irows
return output
if __name__ == '__main__':
lines = r'C:\TEMP\lineCopy.shp'
pts = r'C:\TEMP\line_pts2.shp'
add_points_along_lines(lines, pts, 'Time_sec')
print 'done'
The fields that are added at the end are "LINE_POS", which refers to the distance value along the line and the other is the "SEG_LENGTH", which denotes the segment length between each point.