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.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
S.Rai
  • 309
  • 3
  • 14
  • 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 02 '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 02 '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 02 '16 at 20:29
  • I think the code snippets that you are posting would benefit from being compared against the guidelines offered at http://meta.gis.stackexchange.com/questions/4312 – PolyGeo Sep 03 '16 at 00:14

1 Answers1

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"
Ken
  • 596
  • 2
  • 8