My organization creates a number of layer files for our ArcMap users to access data from web services. Is there any way to use arcpy.Describe to get to the URL of the service referenced by the layer? My testing so far has only yielded paths back to the layer file itself, or a temp folder:

>>> d=arcpy.Describe(r'e:\geodata\ortho_imagery\naip_ca_historical.lyr')
>>> d.catalogPath
>>> l=d.layer
>>> l.catalogPath

I'd also be open to a .NET solution if necessary.

The ultimate goal is to develop a tool that will scan our shared drive for .lyr files, and if they refer to a web service, test its validity.

1 Answer 1


Some arcpy.mapping.Layer objects have a read only property serviceProperties that can be used to check this sort of thing. Two types of layers, ArcSDE and web services, support service properties. serviceProperties is a dictionary that has different key value pairs depending on the layer type. The dictionary of service properties for web services has a key URL that you can use to return the url of that service. However you first need to check if the layer supports serviceProperties, you can print out all of a layers service properties (granted it supports them) like this:

if layer.supports('SERVICEPROPERTIES'):    
     layer_info = ['(Key: %s, Value: %s)' % (key, layer.serviceProperties[key]) for key in layer.serviceProperties.keys()]
     print layer_info

Or to directly check for the URL you would do this:

if layer.supports('SERVICEPROPERTIES'):
    if 'URL' in layer.serviceProperties.keys():
        url = layer.serviceProperties['URL']

See here for more details about the service properties dictionary, scroll down to the Properties section of the page.

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.