2

I am working on a really big script right now where I have a csv file that I have removed rows and columns from, and edited the headers. I need to create one big shapefile for the entire csv file then create individual shape files for the units under one of the headers. I thougt the best way to do this would be to use arcpy.MakeXyEventLayer(), I saw in an arcgis sample script to then use arcpy.GetCount()for the output file of the xyEveveLayer, then arcpy.SaveToLayerFile_management() and arcpy.FeatureClassToShapefile_ conversion, but when I run the script only my csv file is getting edited and there is no layer in the output file. Is there a step I am missing or should this be making my shape.

this is the few lines of code I have used, after all of the csv file editing, to do what is described above:

outLyr = sys.arg[3] # shapefile layer output name
    XYLyr.newLyr(csvOut, lyrOutFile, spRef, sys.argv[4], sys.argv[5]) # x coordinate column; y coordinate column
    print arcpy.GetCount_management(lyrOutFile)
    csv2LYR.saveLYR(lyrOutFile, curDir)
1
  • The duplicate addresses the problem in the title. The secondary question (splitting the shapefile into pieces) is addressed in many threads on our site--a search ought to turn them up.
    – whuber
    Commented Apr 26, 2013 at 20:30

2 Answers 2

2

After making your event layer use the feature class to feature class method, see example below:

# Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(InputCSV, "lng", "lat", Book1_Layer, "", "")

# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(Book1_Layer, outputDir, fcName)

For geoprocessing tasks you can use ModelBuilder to test your process, than export your model out as a python snippet.

2

In your script, you are creating a temporary layer without saving anything permanent. Use Copy Features (Data Management) to make your layer permanent:

arcpy.CopyFeatures_management (lyrOutFile, out_fc) 

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