I'm a bit late to the party, but I have been trying to iterate from an active XLS sheet to my shapefile. I have had no luck trolling through ESRI help sites etc, which simply astounds me (i.e. that I cannot update an Excel sheet and simply update the shapefile to read in the changes).
I don't do well with scripting, also it doesn't resolve my dilemma of having to reformat my point data style each time, which is an additional tedious step.
Has there been any progress on this function? It would seem to me to be a trivial function, but I've had no luck cracking it without introducing multiple complexities.
Thanks.
how can we add layer into TOC or map document i have tried by doing
arcpy.MakeXYEventLayer_management(xls, 'EASTING', 'NORTHING', layer, spa_ref)
arcpy.SetParameter(0,"control_points")
pmxd = arcpy.mapping.MapDocument("CURRENT")
pdf = arcpy.mapping.ListDataFrames(pmxd)[0]
arcpy.mapping.AddLayer(pdf,)
arcpy.CopyFeatures_management(layer, output)
print 'Feature Class Created'
but its not working
arcpy.TableToTable_conversion (layer, outfold, 'LongHornSBM')
import arcpy, os, sys, traceback from os import path as p arcpy.env.workspace = ws = r'C:\Documents\DatabaseData' arcpy.env.overwriteOutput = True arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('WGS 1984') # Variables xls = r'Y:\Strategy by Market Reports and Data\Darden Master SBM Table.xlsx\LHGIS$' layer = 'LongHornSBM' outfold = r'C:\Documents\ArcGIS\DardenMaster.gdb' output = p.join(outfold, 'LongHornSBM') try: arcpy.MakeXYEventLayer_management(xls, 'LONGITUDE', 'LATITUDE', layer) arcpy.CopyFeatures_management(layer, output) print 'Feature Class Created' except: # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n" # Return python error messages for use in script tool or Python Window arcpy.AddError(pymsg) arcpy.AddError(msgs) # Print Python error messages for use in Python / Python Window print pymsg + "\n" print msgs
Ok great. Thank you again.What is 'control_points' in the output variable?I tried running and it seems to have failed to read the lat/longs...try: arcpy.MakeXYEventLayer_management(xls, 'LONGITUDE', 'LATITUDE', layer) arcpy.CopyFeatures_management(layer, output) print 'Feature Class Created'EDIT: I think I figured out why it cant read the XY data. My guess is one of 2 things, or maybe both.1. The table is setup as all VLOOKUP values in excel. It just pulls values from other sheets within the file. 2. Since it is setup as VLOOKUPs, there is a reference number field for row 1, and then the field names in row 2. Im guessing one of those things is causing it to be unable to plot those values.
try: arcpy.MakeXYEventLayer_management(xls, 'LONGITUDE', 'LATITUDE', layer) arcpy.CopyFeatures_management(layer, output) print 'Feature Class Created'
Did the coordinate system .prj files move somewhere else for 10.1? I cant seem to find them. Also, will this work if 1. there are files in the GDB with the same name as the ones I want to put in (ie, can it replace existing files?), and 2. if the Excel table is not on my local drive? Thank you!!
sr = arcpy.SpatialReference(26776) # OR (I think) sr = arcpy.SpatialReference('NAD 1927 StatePlane Iowa South FIPS 1402 (US FEET)')
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('NAD 1927 StatePlane Iowa South FIPS 1402 (US FEET)')
# set the environment setting to overwrite output arcpy.env.overwriteOutput = True # OR table = r'G:\Some\Path\Table' if arcpy.Exists(table): arcpy.Delete_management(table) # Copy table to geodatabase after deleting original here
Thanks for that!! Im reading about relationship classes, but that may be kinda pointless since Ive only got ArcView licenses to work with. Im going to try to play with the scripting option. My boss at my old job wanted to set something up like that, but we never got around to it. Im not really good at understanding the basics of scripting languages, so I have a hard time writing things, but if I need to run a simple process, I can usually get that done.
import arcpy, os, sys, traceback from os import path as p arcpy.env.workspace = ws = r'C:\testing' # Variables xls = r'C:\testing\Cedar_Network.xlsx\Sheet1$' spa_ref = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\State Plane\NAD 1983 (US Feet)\NAD 1983 StatePlane Iowa South FIPS 1402 (US Feet).prj' layer = 'XY_Event' outfold = r'C:\testing\test.gdb' output = p.join(outfold, 'control_points') try: arcpy.MakeXYEventLayer_management(xls, 'EASTING', 'NORTHING', layer, spa_ref) arcpy.CopyFeatures_management(layer, output) print 'Feature Class Created' except: # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n" # Return python error messages for use in script tool or Python Window arcpy.AddError(pymsg) arcpy.AddError(msgs) # Print Python error messages for use in Python / Python Window print pymsg + "\n" print msgs
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.