Guest User

Untitled

a guest
Nov 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import arcpy
  2. import xml.dom.minidom as DOM
  3.  
  4. #define local variables
  5. # wrkspc mxd document directory
  6. # mxdName mxd document name
  7. # con ArcGIS Server Catalog path
  8. # service service name (include service direcotry)
  9. # summary service summary
  10. # tags services tags
  11.  
  12. wrkspc = 'C:/test/'
  13. mxdName = 'sample.mxd'
  14. con = 'GIS Servers/arcgis on localhost_6080 (admin)'
  15. service = 'MyMapService'
  16. summary = 'Population Density by County'
  17. tags = 'county, counties, population, density, census'
  18.  
  19. mapDoc = arcpy.mapping.MapDocument(wrkspc + mxdName)
  20. sddraft = wrkspc + service + '.sddraft'
  21. sd = wrkspc + service + '.sd'
  22.  
  23. # create service definition draft
  24. analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER',
  25. con, True, None, summary, tags)
  26.  
  27. # set service type to esriServiceDefinitionType_Replacement
  28. newType = 'esriServiceDefinitionType_Replacement'
  29. xml = sddraft
  30. doc = DOM.parse(xml)
  31. descriptions = doc.getElementsByTagName('Type')
  32. for desc in descriptions:
  33. if desc.parentNode.tagName == 'SVCManifest':
  34. if desc.hasChildNodes():
  35. desc.firstChild.data = newType
  36. outXml = xml
  37. f = open(outXml, 'w')
  38. doc.writexml( f )
  39. f.close()
  40.  
  41. # stage and upload the service if the sddraft analysis did not contain errors
  42. if analysis['errors'] == {}:
  43. # Execute StageService
  44. arcpy.StageService_server(sddraft, sd)
  45. # Execute UploadServiceDefinition
  46. arcpy.UploadServiceDefinition_server(sd, con)
  47. else:
  48. # if the sddraft analysis contained errors, display them
  49. print analysis['errors']
  50.  
  51. analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER', con, True, 'Maps', summary, tags)
Add Comment
Please, Sign In to add comment