I found the XY spreadsheet to layer file python script, but I would like to take a csv and create the feature class in a geodatabase. Is that possible?
Solved! Go to Solution.
Once you've made your feature layer, run CopyFeatures to save it to a feature class (I save to shapefile below, but you can save it to a gdb):
>>> my_csv = r'C:\junk\csv.csv'
... lyr = arcpy.MakeXYEventLayer_management(my_csv,'x','y','lyr')
... fc = arcpy.CopyFeatures_management(lyr,r'C:\junk\outshp.shp')
Once you've made your feature layer, run CopyFeatures to save it to a feature class (I save to shapefile below, but you can save it to a gdb):
>>> my_csv = r'C:\junk\csv.csv'
... lyr = arcpy.MakeXYEventLayer_management(my_csv,'x','y','lyr')
... fc = arcpy.CopyFeatures_management(lyr,r'C:\junk\outshp.shp')
Perfect, thanks!
If you don't specify a coordinate system up front with the Make XY Event Layer tool, do so after you've created the feature class with Define Projection. This coordinate system is the coordinate system of the XY in the table (often GCS NAD83 or WGS84), not your ArcMap data frame.
In Python the eaisiest way to specify this is with the WKID:
SR = arcpy.SpatialReference(4269) # GCS NAD83
lyr = arcpy.MakeXYEventLayer_management(my_csv,'x','y','lyr',SR)
It took me a while to find the WKIDs so I will post here for convenience.
What are projected coordinate systems?—Help | ArcGIS Desktop
http://desktop.arcgis.com/en/arcmap/latest/map/projections/pdf/projected_coordinate_systems.pdf
What are geographic coordinate systems?—Help | ArcGIS Desktop
http://desktop.arcgis.com/en/arcmap/latest/map/projections/pdf/geographic_coordinate_systems.pdf
thanks Blake, I was looking for those this morning. They are hard to find in the help it seems.
Another site of interest Coordinate system - GIS Wiki | The GIS Encyclopedia
although some of the links are old (to ArcGIS 9.3. help docs)
Another trick is to search for the coordinate system you want on the Coordinate System tab of the Data Frame Properties in ArcMap. The WKID is included as part of the definition:
And http://spatialreference.org -- just make sure the code has been tagged an Esri code to ensure it's in the ArcGIS installed database.
I added this link to my first reply above.
This may help - you may have to tweek the code a bit