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?
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):
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> my_csv <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\junk\csv.csv'</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> lyr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeXYEventLayer_management<SPAN class="punctuation token">(</SPAN>my_csv<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'x'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'y'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'lyr'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> fc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">,</SPAN>r<SPAN class="string token">'C:\junk\outshp.shp'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This may help - you may have to tweek the code a bit
https://github.com/tgirgin23/csv2gdb
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
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 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN><SPAN class="number token">4269</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># GCS NAD83</SPAN> lyr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeXYEventLayer_management<SPAN class="punctuation token">(</SPAN>my_csv<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'x'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'y'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'lyr'</SPAN><SPAN class="punctuation token">,</SPAN>SR<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
Perfect, thanks!
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.