Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

What arcpy module can I use to write a python script to mine for fields of my map service properties and export them to a .tx file? I assume we need to tap into GIS Servers within the ArcCatalog interface?

share|improve this question
    
What kind of properties are you interested in? Layer names? Supported service interfaces? Data paths? –  om_henners Nov 29 '12 at 23:27
    
What version of ArcGIS Server are you on? (edit Q) –  Simon Dec 1 '12 at 12:11
    
Server 10. Trying to access service properties whose fields include service type, service capabilities and parameters, document path, and caching information. You can only get these fields from ArcCatalog>GIS Services>Service Properties dialog box and not from a REST URL. –  pdog Dec 2 '12 at 22:27
add comment

1 Answer 1

Quick and dirty code... substitute the "print" for some code to write to a textfile if thats what you want. You'll notice its hardcoded to one specific layer in a map service. You can enhance to loop through all layers, or even loop through all services on a server THEN all layers, THEN get fields.

import urllib, urllib2, json

def getServiceFields(URL): 

    fURL = URL + "?f=json"

    openURL = urllib2.urlopen(fURL, '').read()    
    outJson = json.loads(openURL)   

    return outJson["fields"]   


if __name__ == "__main__": 

    URL = r"http://sampleserver6.arcgisonline.com/arcgis/rest/services/Water_Network/MapServer/11"

    fields = getServiceFields(URL)

    for f in fields:
        print "Name : {}, Type : {}".format(f["name"], f["type"])

Also for reference, heres what you can get out of "f":

f["alias"]

f["length"]

f["type"]

f["name"]

f["domain"]

(per a 10.1 server, may change for 10.0)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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