Want to iterate through point shapefiles, convert them to polyline shapefiles with unique names

by K. Schuman   Last Updated October 19, 2019 00:22 AM - source

for fc in arcpy.ListFeatureClasses():
    outfc = fc + "_l"
    arcpy.PointsToLine_management(fc, outfc)

it comes up with the error "Output Feature Class: Same as input". Looks like it didn't convert at all, and added an "l" in the case of one file Bacon.shpl instead of what I want (Bacon_l.shp)

I am really bad with for loops and iterators, and I'd do this in ArcMap if I didn't have to manually enter a billion files using the batch feature.



Answers 1


It's probably because you're just appending "_l" to the feature class path , rather than inserting it. And when the feature class is a shapefile, you end up with "filepath.shp" + "_l" which == "filepath.shp_l"

Try:

import os.path
import arcpy

for fc in arcpy.ListFeatureClasses():
    name, ext = os.psth.splitext(fc)
    outfc = name + "_l" + ext
    arcpy.PointsToLine_management(fc, outfc)
user2856
user2856
October 19, 2019 00:00 AM

Related Questions




Model Builder - Iterator and List of Values

Updated April 19, 2017 17:22 PM