1

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
u'e:\\Geodata\\ortho_imagery\\naip_ca_historical.lyr'
>>> l=d.layer
>>> l.catalogPath
u'C:\\Users\\bjorn\\AppData\\Local\\Temp\\3\\NAIP_Historical/California_Historical'

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.

2

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, privacy policy and cookie policy

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