1

I'm trying to add coordinates to values of a .dbf table in ArcGIS 10.2. I'm using the following code:

import arcpy
from arcpy import env
env.workspace = "F:\Otim\interf"

try:
    # Set the local variables
    in_Table = "Ge_A_otim.dbf"
    x_coords = "Longitude"
    y_coords = "Latitude"
    #z_coords = "POINT_Z"  #I don't have Z point...
    out_Layer = "Ge_aa_otim1"
    saved_Layer = r"F:\Otim\interf\Ge_aa_otim1.lyr"

    # Set the spatial reference
    spRef =  arcpy.SpatialReference(102164)
    # Make the XY event layer...
    arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, "")

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

    # Save to a layer file
    arcpy.SaveToLayerFile_management(out_Layer, saved_Layer)

except:
    # If an error occurred print the message to the screen
    print arcpy.GetMessages()

And I have an error:

Failed to execute. Parameters are not valid. ERROR 000732: XY Table: Dataset Ger_Act_otim.dbf does not exist or is not supported Failed to execute (MakeXYEventLayer).

I try to do without code, using function "Add XY Coordinates" and I can't find table.

  • Are you trying to add XY values TO a .dbf file or are you trying to make a point layer FROM XY values already in the .dbf file? Your first line seems to want to 'add to', while the MakeEventLayer call would read XY values already in the file – hgil Sep 2 '16 at 14:41
  • Please do not include try/except in code snippets that you post because that can mask otherwise helpful Python messages. – PolyGeo Sep 2 '16 at 19:09
  • 1
    If script cannot find table and you cannot find it and error message says it does not exist, it's no coincidence. Try to rename it using Windows explorer – FelixIP Sep 2 '16 at 20:29
  • I think the code snippets that you are posting would benefit from being compared against the guidelines offered at meta.gis.stackexchange.com/questions/4312 – PolyGeo Sep 3 '16 at 0:14
2

I believe the issue is that Python treats the backslashes in your paths as escape characters and cannot find your file.

Try changing adding a second backslash to your paths

env.workspace = "F:\\Otim\\interf"

or prefixing a 'r' in front of your path to set it as a raw string.

env.workspace = r"F:\Otim\interf"
  • I tryed this and the error changes to: ERROR 000212: Cannot create XY event source Failed to execute (MakeXYEventLayer). – S.Rai Sep 2 '16 at 14:41
  • Is the data in your X and Y fields numeric? 000212: Cannot create XY event source – Ken Sep 2 '16 at 14:47
  • yes, it is... My values of Latitude and Longitude are in meters anda they are for example: (Long: 192648; Lat: 320546) – S.Rai Sep 2 '16 at 14:49
  • I tryed again and I could do manually, using make XY event layer function, but I really need to use python code to do this.. – S.Rai Sep 2 '16 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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