I have a .csv file that is an exported attribute table that I would like to reconstruct as a polyline shapefile (for reasons beyond my control I cannot access the original shapefile from which the .csv attribute table was exported, nor do I have access to metadata). To reconstruct the polylines, I must:

  1. Import the .csv file,
  2. Display the point data, then
  3. Connect the points in the correct order to make lines.

I am able to complete steps 1) and 2), but am having trouble with step 3).

Here is what the exported .csv attribute table looks like (hiding a few irrelevant columns): enter image description here

It seems like each row represents a line and that the field "the_geom" contains the lat/long of the points that make up the line. I've tried unsuccessfully to use the xy to line and points to line tools to reconstruct.

How can I reconstruct these lines?

  • 3
    Actually, your conversion process is: 1) Read the ASCII fields 2) Write the resulting row. That's it. The geometry is stored in Well-Known Text, from which it is trivial to generate Geometry objects. The most important part is to not do your step two, because that could wreck the geometry. To repeat, this is not a points-to-line task, this is a line to line task. Research how to convert WKT to geometry and you'll be done.
    – Vince
    Jan 3, 2020 at 1:37
  • You can easily do this in Python if you want, but I assume you are not looking for that? Jan 3, 2020 at 10:27
  • Thank you @Vince for you advice, I researched WKT to geometry and was able to solve the problem. Here is a simple script I modified to convert. Jan 3, 2020 at 16:55

1 Answer 1


Convert WKT to geometry using a script such as this (slightly modified code borrowed from this esri community question):

# convert wkt to geometry and compile shapes into a single feature class
import arcpy

File = "C:\\Users\\Team\\Documents\\WKTtest\\WKT.csv"

# dimension the WKT string field and poly ID field
# the field holding the WKT string
field1 = "WKT"
# the field holding the unique ID...
field2 = "Our_ref"

# set up the empty list...
featureList = []

# set the spatial reference to a known EPSG code
sr = arcpy.SpatialReference(27700)
# iterate on table row...
cursor = arcpy.SearchCursor(File)
row = cursor.next()
while row:
    print (row.getValue(field2))
    WKT = row.getValue(field1)
    # this is the part that converts the WKT string to geometry using the defined spatial reference
    temp = arcpy.FromWKT(WKT, sr)
    # append the current geometry to the list

    row = cursor.next()
# copy all geometries in the list to a feature class
arcpy.CopyFeatures_management(featureList, "C:\\Users\\Team\\Documents\\WKTtest\\WKTShapes.shp")

  • 1
    Link-only answers tend to fail over time. A full answer would include a complete procedure within the answer body, with a link for reference.
    – Vince
    Jan 4, 2020 at 5:26

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.