Export XY Event Source to shapefile using python

4367
2
04-08-2015 12:20 PM
NatalieZeleznik
New Contributor

Manually, one can export an XY Event Source to a shapefile by right-clicking on it, then selecting Data>Export Data.  How would I automate this using Python?  There doesn't seem to be a tool for this. 

0 Kudos
2 Replies
DarrenWiens2
MVP Honored Contributor

Have you tried Copy Features?

0 Kudos
JamesCrandall
MVP Frequent Contributor

You can just convert the table source to a Feature Class with da.NumpyArrayToFeatureClass

http://resources.arcgis.com/en/help/main/10.1/index.html#//018w0000001n000000

import arcpy
import numpy
from numpy import genfromtxt

csvFile = r'myfile.csv'
dfarr = genfromtxt(csvFile,delimiter=',')
arrayToConvert = numpy.array(dfarr, numpy.dtype([('X', '<f8'),('Y', '<f8')]))
output = 'H:\Documents\Default.gdb\NumpyToFC'
if arcpy.Exists(output):
     arcpy.Delete_management(output)

arcpy.da.NumPyArrayToFeatureClass(arrayToConvert, output, ("X", "Y"))