Select to view content in your preferred language

Make XY Event Layer  in Python Crashes But Not in Model Builder

4371
16
Jump to solution
01-21-2013 11:02 AM
AdamGuo
New Contributor II
Hi,

I am trying to automate a table (in geodatabase) with lat longs and convert it into a feature class. I first created the steps in model builder where it works fine. But when I export out into Python script and run it without any modifications to the script, it would fail and give me the error below.

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: XY Table: Dataset C:\Spatial.mdb\WELLS does not exist or is not supported
Failed to execute (MakeXYEventLayer)

Any ideas?

Thank you!

I am running Win 7 64 bit 10.1 SP1 with Geoprocessing for SP1 updated as well.

[ATTACH=CONFIG]20937[/ATTACH]
Tags (2)
0 Kudos
16 Replies
AdamGuo
New Contributor II
Here's the attached sample of the PGDB. The reason I am using PGDB is for Microsoft Access. I have a lot of queries, macros and links created to produce the end result table.

Thank you.
0 Kudos
by Anonymous User
Not applicable
I am not sure what is going wrong with yours.  I was able to get this to work:

#Import arcpy module
import arcpy, os

# Set the workspace environment to local file geodatabase
arcpy.env.workspace = ws = r"C:\FoB Oil and Gas\GoM\WorkSpace.gdb"
spa_ref = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Geographic Coordinate Systems\North America\NAD 1927.prj'

try:

    # Local variables:
    tbl = r"C:\FoB Oil and Gas\GoM\3_Compare\Compare.mdb\WELLS"
    lyr = "WELLS_Layer"

    # Process: Make XY Event Layer
    arcpy.MakeXYEventLayer_management(tbl, "SURFACE_LONGITUDE", "SURFACE_LATITUDE", lyr, spa_ref)

    # Print the total rows
    print arcpy.GetCount_management(lyr)

    arcpy.FeatureClassToFeatureClass_conversion(lyr, ws, 'WELLS_Points')
    print 'Created Feature Class'

except:

    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n\t" + \
            str(sys.exc_type) + ": " + str(sys.exc_value) + "\n"
    msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n"
    arcpy.AddError(msgs)
    arcpy.AddError(pymsg)
    print msgs
    print pymsg
    arcpy.AddMessage(arcpy.GetMessages(1))
    print arcpy.GetMessages(1)


I did this using version 10. If you are at 10.1 you will need to find the factory code for the NAD 1927.  Also, not sure if it is causing the problem, but it is best to not have spaces in your folder names.
0 Kudos
T__WayneWhitley
Frequent Contributor
Yeah, probably this isn't your problem, but if I were you (at least to eliminate it as a potential problem), I would not include the final optional 'Z' parameter.  You don't have one to enter here anyway....and I noticed Caleb's code didn't have it.

Other than that, the spatial reference object is interesting......not sure, but I think you need this line to set the spatial ref at 10.1:

sr = arcpy.SpatialReference(factoryCode)

Where factoryCode is the WKID (well-known ID), that isn't so well known (just a small joke there, sorry).  Maybe wrong, but this may set if correctly for you:

sr = arcpy.SpatialReference(104145)

But you have to check it...I got the value from:
http://resources.arcgis.com/en/help/main/10.1/018z/pdf/geographic_coordinate_systems.pdf

See:
SpatialReference (arcpy)
Desktop » Geoprocessing » ArcPy » ArcPy classes
http://resources.arcgis.com/en/help/main/10.1/index.html#//018z0000000v000000
0 Kudos
by Anonymous User
Not applicable
sr = arcpy.SpatialReference(factoryCode)

Where factoryCode is the WKID (well-known ID), that isn't so well known (just a small joke there, sorry). Maybe wrong, but this may set if correctly for you:

sr = arcpy.SpatialReference(104145)


Interesting...I do not know why the 10.1 help says that you have to create the Spatial Reference object like that.  I have 10.1 at work so I was able to test this:

    # Process: Make XY Event Layer,  WKID 4267 is NAD 1927 in 10.1
    arcpy.MakeXYEventLayer_management(tbl, "SURFACE_LONGITUDE", "SURFACE_LATITUDE", lyr, 4267)


This worked perfectly.  Apparently, you can just put the WKID in as the spa ref parameter without using the "sr = arcpy.SpatialReference(104145)" technique.
0 Kudos
T__WayneWhitley
Frequent Contributor
...sorry if a little off topic Adam -- I question your original statement:

"I am running Win 7 64 bit 10.1 SP1 with Geoprocessing for SP1 updated as well."

Did you install 64 bit background geoprocessing?  If so, you may be having trouble reading 32 bit apps...xls, mdb, etc.

If that's your trouble, see Kevin Hibma's comment here:

"If you have 64bit BG and want to execute against 32bit Python (32bit Desktop) because you're using pGDBs, force your script to run against 32bit..."
http://forums.arcgis.com/threads/70241-10.1-sp-1-and-32-64-bit-Python-versions?p=245700#post245700


Also this, if it applies to your situation:
http://blogs.esri.com/esri/arcgis/2012/10/31/announcing-64-bit-geoprocessing/


PS - Thanks to Caleb for that spatial reference info...think Adam will need that as well.

-Wayne
0 Kudos
AdamGuo
New Contributor II
Thank you all for the suggestions. Wayne you were right about the 32/64 bit. Apparently I was running the 64bit python instead of the 32bit. I created a batch to run the script in 32 bit and it worked perfectly. Now I just need to figure out how to hard code it into the scripts when I create them in the future.

Thanks you all again for your help!
0 Kudos
T__WayneWhitley
Frequent Contributor
Then you could run in foreground, or you may heed Chris Snyder's valuable contribution here:

http://forums.arcgis.com/threads/75207-Excel-and-Python-Friends-or-Foes?p=263825#post263825
0 Kudos