CreateImageSDDraft (arcpy)

Summary

The CreateImageSDDraft function is the first step to automating the publishing of a mosaic dataset or raster dataset as an Image Service using ArcPy. The output created from the CreateImageSDDraft is a Service Definition Draft (.sddraft) file, which is a combination of a mosaic dataset in the geodatabase or a raster dataset, information about the server, and a set of service properties. This service definition draft can be staged as service definition then uploaded to a specified ArcGIS server as an image service.

Information about the server includes the server connection or server type being published to, the type of service being published, metadata for the service (Item info), and data references (whether or not data is being copied to the server).

NoteNote:

A draft service definition does not contain data. A draft service alone cannot be used to publish a service.

Syntax

CreateImageSDDraft (raster_or_mosaic_layer, out_sddraft, service_name, {server_type}, {connection_file_path}, {copy_data_to_server}, {folder_name}, {summary}, {tags})
ParameterExplanationData Type
raster_or_mosaic_layer

The raster layer or mosaic layer that you want to publish.

String
out_sddraft

A string that represents the path and file name for the output Service Definition Draft (.sddraft) file.

String
service_name

A string that represents the name of the service. This is the name people will see and use to identify the service. The name can only contain alphanumeric characters and underscores. No spaces or special characters are allowed. The name cannot be more than 120 characters in length.

String
server_type

A string representing the server type. If a connection_file_path parameter is not supplied, then a server_type must be provided. If a connection_file_path parameter is supplied, then the server_type is taken from the connection file. In this case, you can choose FROM_CONNECTION_FILE or skip the parameter entirely.

  • ARCGIS_SERVERArcGIS for Server server type.
  • FROM_CONNECTION_FILEGet the server_type as specified in the connection_file_path parameter.

(The default value is ARCGIS_SERVER)

String
connection_file_path

A string that represents the path and file name to the ArcGIS for Server connection file (.ags).

(The default value is None)

String
copy_data_to_server

A Boolean that indicates whether the source data referenced by the mosaic dataset, the mosaic dataset itself, or the raster dataset published as an image service will be copied to the server or not.

The copy_data_to_server parameter is only used if the server_type is ARCGIS_SERVER and the connection_file_path isn't specified. If the connection_file_path is specified, then the server's registered data stores are used. For example, if the workspace that contains the source data referenced by the mosaic dataset—the mosaic dataset itself or raster dataset registered with the server—then copy_data_to_server will always be False. Conversely, if the workspace that contains the source data referenced by the mosaic dataset—the mosaic dataset or raster dataset is not registered with the server—then copy_data_to_server will always be True.

  • FalseThe data will not be copied to the server. This is the default.
  • TrueThe data will be copied to the server.

(The default value is False)

Boolean
folder_name

A string that represents a folder name to which you want to publish the service definition. If the folder does not currently exist, it will be created. The default folder is the server root level.

(The default value is None)

String
summary

A string that represents the Item Description Summary.

Use this parameter to override the user interface summary or to provide a summary if one does not exist.

(The default value is None)

String
tags

A string that represents the Item Description Tags.

Use this parameter to override the user interface tags or to provide tags if they do not exist.

(The default value is None)

String

Code Sample

CreateImageSDDraft example 1

Create an image service definition draft file.

import arcpy

ws = "C:/workspace"
mdpath = os.path.join(ws, "fgdb.gdb/mdDEM")      
con = os.path.join(ws, "myserver_6080 (publisher).ags")
service = 'dem_service'
sddraft = os.path.join(ws, service + '.sddraft')

arcpy.CreateImageSDDraft(mdpath, sddraft, service, 'ARCGIS_SERVER', 
                         con, True, None, "Publish las MD", 
                         "las,image service")
CreateImageSDDraft example 2

Publish an image service from a mosaic dataset.

# It is recommended that you set the default mosaic dataset properly before
# publishing. A connection to ArcGIS Server must be established in the
# Catalog window of ArcMap before running this script

import arcpy
import os
import sys

# Define local variables:

# The folder for service definition draft and service definition files
MyWorkspace = r"\\myserver\ArcPyPublishing"
Name = "OrthoImageService"
InputData = r"\\myserver\ArcPyPublishing\fgdb.gdb\ortho_images"
Sddraft = os.path.join(MyWorkspace, Name + ".sddraft")
Sd = os.path.join(MyWorkspace, Name + ".sd")
con = os.path.join(MyWorkspace, "arcgis on myserver_6080 (admin).ags")

# Create service definition draft
try:
    print("Creating SD draft")
    arcpy.CreateImageSDDraft(InputData, Sddraft, Name, 'ARCGIS_SERVER', con, 
                             False, None, "Ortho Images",
                             "ortho images,image service")
except Exception as err:
    print(err[0] + "\n\n")
    sys.exit("Failed to create SD draft")

# Analyze the service definition draft
analysis = arcpy.mapping.AnalyzeForSD(Sddraft)
print("The following was returned during analysis of the image service:")
for key in analysis.keys():

    print("---{}---".format(key.upper()))

    for ((message, code), layerlist) in analysis[key].iteritems():
        print("    {} (CODE {})".format(message, code))
        print("       applies to: {}".format(
            " ".join([layer.name for layer in layerlist])))

# Stage and upload the service if the sddraft analysis did not contain errors
if analysis['errors'] == {}:
    try:
        print("Adding data path to data store to avoid copying data to server")
        arcpy.AddDataStoreItem(con, "FOLDER", "Images", MyWorkspace,
                               MyWorkspace)

        print "Staging service to create service definition"
        arcpy.StageService_server(Sddraft, Sd)

        print "Uploading the service definition and publishing image service"
        arcpy.UploadServiceDefinition_server(Sd, con)

        print "Service successfully published"
    except arcpy.ExecuteError:
        print(arcpy.GetMessages() + "\n\n")
        sys.exit("Failed to stage and upload service")

    except Exception as err:
        print(err[0] + "\n\n")
        sys.exit("Failed to stage and upload service")
else:
    print("Service was not published because of errors found during analysis.")
    print(analysis['errors'])

Related Topics

3/3/2014