CreateImageSDDraft (arcpy)

摘要

CreateImageSDDraft 函数是使用 ArcPy 自动发布镶嵌数据集或栅格数据集作为“影像服务”的第一步。基于 CreateImageSDDraft 创建的输出是服务定义草稿 (.sddraft) 文件,该文件由栅格数据集或地理数据库中的镶嵌数据集、服务器信息以及一组服务属性组合而成。该服务定义草稿可作为服务定义过渡,然后作为影像服务上传至指定的 ArcGIS 服务器。

服务器信息包括服务器连接或已发布的服务器类型,正在发布的服务的类型,服务的元数据(项目信息)和数据参考(是否向服务器复制数据)。

注注:

草稿服务定义不包含数据。草稿服务不能单独用于发布服务。

语法

CreateImageSDDraft (raster_or_mosaic_layer, out_sddraft, service_name, {server_type}, {connection_file_path}, {copy_data_to_server}, {folder_name}, {summary}, {tags})
参数说明数据类型
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.

(默认值为 ARCGIS_SERVER)

String
connection_file_path

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

(默认值为 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.

(默认值为 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.

(默认值为 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.

(默认值为 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.

(默认值为 None)

String

代码实例

CreateImageSDDraft 示例 1

创建影像服务定义草稿文件。

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 示例 2

通过镶嵌数据集发布影像服务。

# 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'])

相关主题

5/10/2014