AnsweredAssumed Answered

Utilizing Functions with Arcpy

Question asked by jack.r.jenkins on Nov 12, 2018
Latest reply on Nov 27, 2018 by MClaggett-esristaff

I need to re-structure my script so the line & feature class creation happen in functions

rather than the being spelled out in the main part of my script. I then, need to separate

the function into a separate file and make the adjustments necessary in the main script to

allow it to still utilize the functions.

My script;

# Use a .txt file to generate a line shapefile
import arcpy
from collections import defaultdict
import pandas as pd 

= "C:\\Data"
arcpy.env.workspace = outFolder

#Read textfile and store in dictionary
df = pd.read_csv(r"C:\\Data\\WalkingPaths.txt", header=None,names=["WalkingPath", "X", "Y"]) 
= defaultdict(list)
for index, row in df.iterrows():   

#Create feature class
fc = "WalkingPaths.shp"spatRef = arcpy.SpatialReference(26913)
arcpy.CreateFeatureclass_management(out_path=outFolder, out_name=fc, geometry_type = "POLYLINE", spatial_reference=spatRef)
arcpy.AddField_management (in_table = fc, field_name = "WalkingPath", field_type = "TEXT")

#Insert polylines and attribute
insertCursor = arcpy.da.InsertCursor (fc, ["SHAPE@","WalkingPath"])
for ranch, points in d.iteritems(): #d.items() in python 3   

del insertCursor