# ArcGIS Error: Cannot set input into parameter spatial_reference

I'm using ArcGIS 10.2. I can do "add XY data as layer" to associate latitude and longitude to a .dbf table, but when I try to do the same with python script it gives me an error:

Python code:
import arcgisscripting, sys, string, os
gp = arcgisscripting.create()
in_Table = "F:\Otim\interf\cg_rea.dbf"
in_x = "Latitude"
in_y = "Longitude"
out_Layer = "cg_rea_otim"
spref = "Coordinate Systems\Projected CoordinateSystems\Lisboa_Hayford_Gauss_IGeoE.prj"
gp.MakeXYEventLayer(in_Table, in_x, in_y, out_Layer, spref) #line where is the error!


Error: Runtime error Traceback (most recent call last): File "", line 191, in ExecuteError: ERROR 000622: Failed to execute (Make XY Event Layer). Parameters are not valid. ERROR 000628: Cannot set input into parameter spatial_reference.

• Maybe try using the full path to the .prj file? Aug 23 '16 at 14:13
• You should use arcpy.SpatialReference(code of projection) to set the spatial reference variable Aug 23 '16 at 14:26
• How I can do this? @MacroZED Aug 23 '16 at 14:34
• What version of ArcGIS are you using? Aug 23 '16 at 14:35
• I'm using ArcGIS 10.2 Aug 23 '16 at 14:36

As you have ArcGIS 10.2, it would be better to use ArcPy. The reference system you have mentioned is http://spatialreference.org/ref/esri/lisboa-hayford-gauss-igeoe/ with the code 102164.

Therefore try the following:

import arcpy, sys, string, os
arcpy.env.workspace = r"path\to\work\area"

in_Table = r"F:\Otim\interf\cg_rea.dbf"
in_x = "Longitude"
in_y = "Latitude"
out_Layer = "cg_rea_otim"
spref =  arcpy.SpatialReference(102164)
arcpy.MakeXYEventLayer_management(in_Table, in_x, in_y, out_Layer, spref)

• I tryed this @MacroZED but it gives me other error: Runtime error Traceback (most recent call last): File "<string>", line 202, in <module> AttributeError: 'module' object has no attribute 'MakeXYEventLayer' Aug 23 '16 at 14:54
• sorry, the actual tool is arcpy.MakeXYEventLayer_management. Ive edited the code to reflect this. Aug 23 '16 at 15:01
• Now it runs without problems but show values on a wrong place on map... Aug 23 '16 at 15:07
• What format are you lats and longs in the DBF? They must be in Decimal Degrees in order for the MakeXYEvent tool to work. Aug 23 '16 at 15:08
• Yes I have in Decimal Degrees, and when I did manually, usinf File->Add data->Add XY Data it worked, but now, using python, it puts values on a different place.. Aug 23 '16 at 15:13