Workspace Issue Creating Layer

287
1
Jump to solution
04-28-2022 01:23 PM
ssintelmann
New Contributor III

Following on previous post, I imported a bunch of tables into GDB using ExcelToTable().  As such the workspace was set to the location of my Excel Files.  Tables import fine.

When try make a feature using arcpy.MakeXYEventLayer_management later in script, I get an error indicating the table doesn't exist, and the layer already exists.  Is this how I have the workspace set, or am I really messing up some other way?

import pandas as pd
import arcpy, os, re

# Variables
arcpy.env.workspace = r'C:\Data\working\EBS16\raw_sonar_files'
outputGDB = r"C:\Data\working\EBS16\EBS_16_analysis_display\default.gdb"
finalOUT = r"C:\Data\working\EBS16\EBS_16_analysis_display\default.gdb\em710vals\em50_"
spref = arcpy.SpatialReference(26903)
arcpy.env.overwriteOutput = True

try:
    for file in arcpy.ListFiles("*.xlsx"):
        f = os.path.join(arcpy.env.workspace, file)
        # Get excel sheets
        sheetNames = pd.ExcelFile(f).sheet_names
        # iterate through sheets
        for sheet in sheetNames:
            # Replace non alphanumeric characters with underscore
            sheetName = re.sub(r'[^0-9a-zA-Z]+', r'_', sheet)
            # create name for temp layer in XY event theme
            outLyr = sheetName + '_lyr'
            # Convert sheet to GDB table
            arcpy.conversion.ExcelToTable(f, os.path.join(outputGDB, sheetName), sheet, 1, '')
            # make XY Layer
            arcpy.MakeXYEventLayer_management(sheet,'easting', 'northing', outLyr, spref)
            outFeat =  finalOUT + sheetName # naming convention
            arcpy.management.CopyFeatures(outLyr, outFeat) # make lyr permanent
except Exception as e:
    print("Error: " + e.args[0])

 

0 Kudos
1 Solution

Accepted Solutions
ssintelmann
New Contributor III

Solved....changed line 25 to this and it worked. 

arcpy.MakeXYEventLayer_management(os.path.join(outputGDB, sheetName),'easting', 'northing', outLyr, spref)

View solution in original post

0 Kudos
1 Reply
ssintelmann
New Contributor III

Solved....changed line 25 to this and it worked. 

arcpy.MakeXYEventLayer_management(os.path.join(outputGDB, sheetName),'easting', 'northing', outLyr, spref)

0 Kudos