Select to view content in your preferred language

arcpy SDE layer file data source issue

2580
1
10-05-2011 07:45 AM
RyanKelley
Deactivated User
To simply state my problem...

I have two layers in my TOC. They both have the same SDE data source. However, one was added as a layer file. The issue is that I am trying to get the spatial reference for any layer in the TOC and when I get to the layer added as a layer file, I get a runtime error when I try to describe the spatial reference.

for lyr in lyrList:
    print lyr.name
    print lyr.dataSource
    desc = arcpy.Describe(lyr.dataSource)
    print desc.spatialReference.name


In line 3 above, my dataSource for the layer file points to the "C:\Documents and Settings\...\bnd", while the non-layer file points to "Database Connections\me@1.sde\bnd"

My error is in line 4 on the layer file: "Runtime error <type 'exceptions.IOError'>: C:\Documents and Settings\bhaney\Application Data\ESRI\ArcCatalog\orwa_sde@orsovctr.sde\OSODBA.Plan_Area_Boundary\OSODBA.PLANBDY_POLY does not exist"

Is this a configuration issue? Is this a known issue?

thank you,
ryan
0 Kudos
1 Reply
JeffBarrette
Esri Regular Contributor
I think I know the problem.  The simple solution is to first try:

desc = arcpy.Describe(lyr)       
and not   desc = arcpy.Describe(lyr.dataSource)

The longer explanation:

I had someone in my office sent me a layer file created using 9.3 Desktop to a 9.3 SDE (as well as a 10.0 layer file pointing to a 10.0 SDE).  When I added their layer file to my 10.0 map document it displayed just fine, that is because we are on the same network and I can connect to the same SDE server as they can (I'm thinking this is similar to your workplace environment).

But when I run the following I get the same error message that you are seeing:

>>> mxd = arcpy.mapping.MapDocument("current")
>>> lyr = arcpy.mapping.ListLayers(mxd)[0]
>>> print lyr.dataSource
C:\Users\UserName\AppData\Roaming\ESRI\ArcCatalog\demo.sde\sde.DBO.layer
>>> desc = arcpy.Describe(lyr.dataSource)

Runtime error <type 'exceptions.IOError'>: "C:\Users\UserName\AppData\Roaming\ESRI\ArcCatalog\demo.sde\sde.DBO.layer" does not exist

This is because the layer file is persisting the original connection information as a property.  When I print lyr.dataSource I get the path to the connection file above.  The .sde file does NOT exist on my local machine so we should expect it to fail because that is what it is looking for.

When we remove the lyr.dataSource and use

desc = arcpy.Describe(lyr)
>>> print desc.spatialReference.name
GCS_WGS_1984

It works because it is using the current connection info rather than the property stored on the layer file.

If I create a new local connection and if I perform a lyr.replaceDataSource using my local SDE connection file info, both methods work without error.

Jeff
0 Kudos