Zusammenfassung
Analyzes Service Definition Draft (.sddraft) files to determine suitability and sources of potential performance issues before converting a Service Definition Draft file to a Service Definition (.sd) file.
Diskussion
An important task that you can perform is analyzing your Service Definition Draft file to identify errors and other potential issues that you may need to address before you can create a Service Definition file. AnalyzeForSD can be used with Service Definition Drafts for map, geoprocessing and image services. This function returns a Python dictionary containing errors, warnings and messages. For example, when working with Service Definition Drafts for map services, this function can:
- Help you identify layer and symbology types that are not supported for optimized map drawing performance.
- Show warnings for issues that can potentially slow down display performance.
- List other information messages about your map document that can help you optimize its performance as a map service.
Analysis for a map Service Definition Draft file is based on many factors including the data used by the map; map, layer, and symbol properties; set service properties such as chosen capabilities and associated properties the service will support; and the server type hosting the service. You will see three types of messages in the Python dictionary: errors, warnings, and information.
Errors for a map Service Definition Draft file typically refer to your map's use of map layer types or display options that are not supported for map services. All errors must be repaired before you can create a Service Definition file. Warnings and other messages identify issues that may affect drawing performance and appearance. Warnings alert you to issues in which drawing performance or drawing appearance may be affected, but these issues do not preclude you from converting the Service Definition Draft file to a Service Definition file.
After analyzing the Service Definition Draft using AnalyzeForSD, it can then be converted to a fully consolidated Service Definition (.sd) file using the Stage Service geoprocessing tool. Staging compiles all the necessary information needed to successfully publish the GIS resource. If you have chosen to copy data to the server, the data will be added when the Service Definition Draft is staged. Finally, the Service Definition file can be uploaded and published as a GIS service to a specified GIS server using the Upload Service Definition geoprocessing tool. This step takes the Service Definition file, copies it onto the server, extracts required information and publishes the GIS resource. For more information, see the overview of the Publishing toolset.
The functions to create Service Definition Drafts for map, geoprocessing, image and geocoding services are:
Syntax
AnalyzeForSD (sddraft)
Parameter | Erläuterung | Datentyp |
sddraft | A string that represents the path and file name for the Service Definition Draft (.sddraft) file. | String |
Rückgabewert
Datentyp | Erläuterung |
Dictionary | Returns a Python Dictionary of information messages, warnings, and errors. |
Codebeispiel
AnalyzeForSD example 1
The following script analyzes a Service Definition Draft (.sddraft) file to identify potential performance bottlenecks and map errors that you may need to address before you can create a Service Definition (.sd) file.
import arcpy
analysis = arcpy.mapping.AnalyzeForSD(r"C:\Project\Counties.sddraft")
for key in ('messages', 'warnings', 'errors'):
print "----" + key.upper() + "---"
vars = analysis[key]
for ((message, code), layerlist) in vars.iteritems():
print " ", message, " (CODE %i)" % code
print " applies to:",
for layer in layerlist:
print layer.name,
print
AnalyzeForSD example 2
The following script demonstrates the complete publishing of map services using arcpy.mapping workflow. Automating the publishing of map services can be accomplished by using a combination of arcpy.mapping functions and the geoprocessing tools in the Publishing toolset. The workflow begins with a map document that you want to publish. First, use the arcpy.mapping function CreateMapSDDraft to create a service definition draft. Next, you should analyze the service definition draft for issues that could prevent you from publishing successfully by using the AnalyzeForSD function. After analyzing the service definition draft and addressing serious issues, it is time to stage the service definition. Staging takes the service definition draft and consolidates all the information needed to publish the service into a complete service definition. Use the Stage Service geoprocessing tool to stage the service definition. Finally, use the Upload Service Definition geoprocessing tool to upload the service definition to the server and publish the map service.
import arcpy
# define local variables
wrkspc = 'C:/Project/'
mapDoc = arcpy.mapping.MapDocument(wrkspc + 'counties.mxd')
con = r'GIS Servers\arcgis on MyServer_6080 (admin).ags'
service = 'Counties'
sddraft = wrkspc + service + '.sddraft'
sd = wrkspc + service + '.sd'
# create service definition draft
arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER', con, True, None)
# analyze the service definition draft
analysis = arcpy.mapping.AnalyzeForSD(sddraft)
# stage and upload the service if the sddraft analysis did not contain errors
if analysis['errors'] == {}:
# Execute StageService
arcpy.StageService_server(sddraft, sd)
# Execute UploadServiceDefinition
arcpy.UploadServiceDefinition_server(sd, con)
else:
# if the sddraft analysis contained errors, display them
print analysis['errors']