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


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
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')


  • 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 '19 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? Aug 22 '19 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 '19 at 14:11
  • 2
    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 '19 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? Aug 22 '19 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.

The right code is:

arcpy.JoinField_management(r'D:\out\test.gdb\line', 'FID', r'D:\out\test.gdb\line_points', 'FID')
arcpy.DeleteField_management(r'D:\out\test.gdb\line', '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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.