0

I have a table (.dbf table) and I need to display on map its values. In this table I have fields: Value to display, longitude(at meters), latitude (at meters). When I right click in this layer and select display xy data, it works but I need to use Python to do this in order to use an automatically tool.

So I used make XY event layer with Arcpy:

import arcpy, sys, string, os
arcpy.env.workspace = r"path\to\work\area"
in_Table_GR = r"F:\ArcGIS\Trab\Model\Result_ot\Ge_P_R_Sub_Otim.dbf"
in_y_GR = "Latitude"
in_x_GR = "Longitude"
out_Layer_GR = "P_r_g_otim"
spref =  arcpy.SpatialReference(102164) 
arcpy.MakeXYEventLayer_management(in_Table_GR, in_x_GR, in_y_GR, out_Layer_GR, spref)

And it gives me an error:

Runtime error  Traceback (most recent call last):   File "<string>", line 1280, in <module>   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6381, in MakeXYEventLayer     raise e ExecuteError: ERROR 000212: Cannot create XY event source Failed to execute (MakeXYEventLayer).

And if I execute function MakeXYEventLayer manually I get the same error. It only work's if I use "display xy data" when I click on this layer.

What is the problem and how can I solve this?

2
  • 1
    Please use "Code" or "Quote" formatting to make error messages legible.
    – Vince
    Commented Sep 5, 2016 at 16:21
  • 2
    what do you mean by "longitude (at meters) and latitude (at meters)"? Latitude and Longitude are not measured in meters. Do you want to convert the values to meters? or do you want latitude and longitude values out of that column (just the values as they exist in the table)? Commented Sep 5, 2016 at 17:21

1 Answer 1

2

Looks like your input coordinates are in lat/lon (a geographic coordinate system), but you are defining the spatial reference as factory code 102164, which is a projected coordinate system (Lisboa_Hayford_Gauss_IGeoE). The spatial reference needs to be the same as the input coordinates.

Your Answer

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

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