# ArcPy from points to lines keeping points attributes?

I have a script in ArcPy that read a CSV file like this:

FID,LonDD,LatDD,Length,Depth,Type,Label,Date/Time
1,-1.090261,59.887594,,5,A,Text,041100ZAUG19
1,-1.090261,59.854044,,5,A,Text,041100ZAUG19
1,-1.104367,59.831088,,5,A,Text,041100ZAUG19
1,-1.129053,59.785178,,5,A,Text,041100ZAUG19
2,-0.164150843,60.63374438,,1,B,Text,041100ZAUG20
2,-0.380170968,60.52978211,,1,B,Text,041100ZAUG20
2,-0.436680462,60.5024162,,1,B,Text,041100ZAUG20
2,-0.5844909,60.43050015,,1,B,Text,041100ZAUG20
3,0.311851222,60.34566342,,2,C,Text,041100ZAUG21
3,0.031944655,60.31490018,,2,C,Text,041100ZAUG21
3,-0.283586398,60.28072305,,2,C,Text,041100ZAUG21
3,-0.468049486,60.26297731,,2,C,Text,041100ZAUG21


and it creates lines following the FID column (each value of FID correspond to a different line, i.e. FID=1 is the first line and each row is a vertex of the line), but when I open in ArcMap I don't have the attributes. I lose them when I use arcpy.PointsToLine_management.

Is there a way to keep them? Maybe for each point of the line?

This is an extract of the script I use:

import archook

# Create AML python environment
archook.get_arcpy()
import arcpy

spRef = r"Coordinate Systems/Geographic Coordinate Systems/World/WGS 1984.prj"

arcpy.CreateFileGDB_management(r'D:\out', 'test.gdb')

# Make the XY event and save to layer file
arcpy.MakeXYEventLayer_management(r'D:\in\data.csv', 'LonDD', 'LatDD', r'D:\in\data', spRef, None)

# Save to layer file
arcpy.SaveToLayerFile_management(r'D:\in\data', r'D:\out\line')

# Convert layer file to gdb. file
arcpy.env.workspace = r'D:\out'
arcpy.CopyFeatures_management(r'D:\out\line.lyr', r'D:\out\test.gdb\line_points')

# Determine name of new line feature class - takes name of input file
arcpy.PointsToLine_management(r'D:\out\test.gdb\line_points', r'D:\out\test.gdb\line', 'FID')

arcpy.Delete_management(r'D:\out\test.gdb\line_points')

os.remove(r'D:\out\line.lyr')

• It's not possible to keep more than a measure value per vertex without building a lookup table for the ancillary data (and picking which attribute is associated with which vertex may be a challenge) – Vince Aug 22 at 13:19
• @Vince does this mean that only points can have more than 1 attribute? Can't I give any attribute to the whole line based on the ones of the points? – cicciodevoto Aug 22 at 14:06
• A point layer can have attributes by point. A line layer has attributes by line. While it's possible to add attributes per vertex, it's very nearly worst practice (normal form is best practice, which would be one row per vertex). – Vince Aug 22 at 14:11
• After you run your script and created your lines, simply run Join Field and join on FID to pass over the rest of the values as they are all constant per FID. – Hornbydd Aug 22 at 14:14
• @Hornbydd I added this line to my code arcpy.JoinField_management(r'D:\out\test.gdb\line_points', 'FID', r'D:\out\test.gdb\line', 'FID') after arcpy.PointsToLine_management, but I don't have the attributes, line_points has all the attributes I thought to take them from there. What mistake did I make? – cicciodevoto Aug 22 at 14:56

Following @Hornbydd suggestion I added arcpy.JoinField_management to my code, but I made the mistake to switch the input table with the output one.
arcpy.JoinField_management(r'D:\out\test.gdb\line', 'FID', r'D:\out\test.gdb\line_points', 'FID')

I added arcpy.DeleteField_management because the final result has twice FID, if I find a better way to do it, I will update the answer.