0

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.

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

1 Answer 1

2

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) 
9
  • 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'
    – S.Rai
    Aug 23, 2016 at 14:54
  • sorry, the actual tool is arcpy.MakeXYEventLayer_management. Ive edited the code to reflect this.
    – MacroZED
    Aug 23, 2016 at 15:01
  • Now it runs without problems but show values on a wrong place on map...
    – S.Rai
    Aug 23, 2016 at 15:07
  • 1
    What format are you lats and longs in the DBF? They must be in Decimal Degrees in order for the MakeXYEvent tool to work.
    – MacroZED
    Aug 23, 2016 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..
    – S.Rai
    Aug 23, 2016 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.