[GIS] ArcGIS Error: Cannot set input into parameter spatial_reference

arcgis-10.2arcpy

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.

Best Answer

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) 
Related Question