GeoprocessingSharingDraft
汇总
可通过 GeoprocessingSharingDraft 类创建 Web 工具或地理处理服务 的服务定义草稿文件 (.sddraft)。
讨论
可使用 CreateSharingDraft 函数创建 GeoprocessingSharingDraft 对象,或使用关键字参数直接创建 GeoprocessingSharingDraft 对象。
要共享 Web 工具,将
serverType参数设置为FEDERATED_SERVER,将serviceType参数设置为WEB_TOOL。要共享地理处理服务,将
serverType参数设置为STANDALONE_SERVER,将serviceType参数设置为GP_SERVICE。
配置 GeoprocessingSharingDraft 对象后,可以使用 exportToSDDraft 方法将其保存到服务定义草稿文件 (.sddraft)。 随后即可使用 过渡服务 和 上传服务定义 工具将其过渡和共享给 ArcGIS Enterprise 或 ArcGIS Server。 有关详细信息,请参阅 什么是 arcpy.sharing 模块 。
语法
GeoprocessingSharingDraft(**kwargs)
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
**kwargs |
All properties supported by the |
String |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
GPStringValues (读取和写入) |
参数名称的列表,发布后,其数据类型将变为字符串。 如果 web 工具中包含多个工具,则必须使用工具名称限定参数名称,例如 |
List |
|
capabilities (读取和写入) |
指定服务将支持的功能。
要同时设置 |
String |
|
choiceLists (读取和写入) |
通过 Web 工具或地理处理服务中的 选项列表输入模式 ,限制所有输入参数的值。 在使用此属性之前,必须先创建选项列表及其值;不能使用此属性向选项列表添加新值。 如果具有要素或栅格输入,则必须先 为选项列表中的每个值创建图层 ,然后使用此属性限制这些值。 该属性使用一个字典,该字典以服务任务和参数名称为键,以字符串值列表为值,例如 |
Dictionary |
|
constantValues (读取和写入) |
要设置为常量的参数名称列表。 如果包含多个工具,则必须使用工具名称限定参数名称,例如 |
List |
|
convertFeatureLayerURL (读取和写入) |
指定要素图层 URL 是否将转换为文件地理数据库要素类。 此属性用于为工具输入、输出参数或工程数据保留要素图层或服务的 URL。 仅在发布到 ArcGIS Enterprise 或 ArcGIS Server 11.2 及更高版本时使用此参数。
|
Boolean |
|
copyDataToServer (读取和写入) |
指定是否将结果中引用的数据复制到服务器。
|
Boolean |
|
description (读取和写入) |
Web 工具或地理处理服务的描述。 默认值为 |
String |
|
draftValue (读取和写入) |
将用于创建服务定义草稿的地理处理 |
List |
|
enableOutputFeatureService (读取和写入) |
指定可选的 输出要素服务名称 参数是否可使用名称 要将此属性设置为 如果未指定值,则当满足以下所有条件时,此属性将自动设置为
有关输出要素服务的详细信息,请参阅 将 Web 工具与输出要素服务一起使用 。 |
Boolean |
|
enableOutputImageService (读取和写入) |
指定可选的 输出影像服务 参数是否可使用名称 要将此属性设置为 有关输出影像服务的详细信息,请参阅 将 Web 工具与输出影像服务一起使用 。 |
Boolean |
|
executionType (读取和写入) |
指定客户端(使用任务的应用程序)如何与服务器进行交互以及如何从任务获取结果。 ArcGIS Pro 可以本地处理两种处理类型。 默认值为
|
String |
|
maxInstances (读取和写入) |
Web 工具或服务可以启动并可供使用的最大实例数。 对于频繁使用的 Web 工具或服务,您可以提高该值。 请确保服务器具有的硬件足以支持指明的最大实例数。 |
Integer |
|
maxUsageTime (读取和写入) |
一个服务能被使用的最长时间(以秒计)。 对于长时间运行的地理处理任务,可以将默认值 600 秒(10 分钟)延长。 或者,您可以减少这一时间,以确保客户端不会错误地应用服务。 |
Integer |
|
maxWaitTime (读取和写入) |
客户端在超时之前将等待连接到实例的最长时间(以秒为单位)。 当所有实例都在忙于处理请求时,随后的请求将排队。 如果在实例变为可用状态之前超时,则任务会失败。 默认值为 60。 |
Integer |
|
maximumRecords (读取和写入) |
Web 工具或服务可以返回给客户端的最大结果数。 将此值设置成一个较大数值意味着 GIS 服务器可以将该数量的单个记录或要素发送到客户端。 如果您不希望返回任何要素,请将此值设为 0(零)。 通常情况下,只有当您启用通过地图服务查看结果时才将此值设为零。 默认值为 1000。 |
Integer |
|
messageLevel (读取和写入) |
指定将用于 Web 工具或地理处理服务的消息级别。 以下是服务返回到客户端的有效消息级别的列表:
默认值为 |
String |
|
minInstances (读取和写入) |
服务将要启动并可供使用的最少实例数。 对于频繁使用的服务,您可以提高该值。 默认值为 1。 |
Integer |
|
offline (读取和写入) |
指定是否保存 离线服务定义 。 默认值为
|
Boolean |
|
offlineTarget (读取和写入) |
指定将发布服务定义的目标服务器版本。 指定一个版本可确保服务定义包含与服务器兼容的内容。 仅在属性
|
String |
|
overwriteExistingService (读取和写入) |
指定是否覆盖现有 Web 工具或地理处理服务。 默认值为 |
Boolean |
|
portalFolder (读取和写入) |
将作为 Web 工具发布的门户文件夹的名称。 默认文件夹是 我的内容 中的根文件夹。 仅当 |
String |
|
removeDefaultValues (读取和写入) |
参数名称的列表,将在 web 工具中移除其默认值。 如果 web 工具中包含多个工具,则必须使用工具名称限定参数名称,例如 |
List |
|
resultMapService (读取和写入) |
指定是否可采用地图形式查看服务所有任务的结果(以及任务的其他结果)。 当使用 当为 |
Boolean |
|
serverFolder (读取和写入) |
要发布到服务器的文件夹名称。 如果该文件夹当前不存在,则将创建该文件夹。 默认的文件夹为服务器根级别。 默认值为 |
String |
|
serverType (读取和写入) |
指定创建共享草稿和设置支持共享时所使用的服务器类型。
|
String |
|
serviceName (读取和写入) |
Web 工具或地理处理服务的名称。 用户可以看到该名称并使用该名称来识别服务。 名称只能包含字母数字字符和下划线。 对于 Web 工具,允许使用空格。 对于地理处理服务,不允许使用空格或特殊字符。 名称不能超过 120 个字符。 默认值为 |
String |
|
serviceType (读取和写入) |
指定创建共享草稿时和共享时使用的服务类型。 |
String |
|
summary (读取和写入) |
Web 工具或服务摘要。 使用此属性可以覆盖用户界面摘要,如果摘要不存在,则将提供摘要。 此处提供的摘要不会保留回原始地理处理工具中。 默认值为 |
String |
|
tags (读取和写入) |
Web 工具或服务标签。 使用此属性可以覆盖用户界面标签,如果标签不存在,则将提供标签。 此处提供的标签不会保留回原始地理处理工具中。 默认值为 |
String |
|
targetServer (读取和写入) |
将发布 Web 工具 或 地理处理服务 的服务器。 如果 如果 如果
|
String |
方法
analyzeSDDraft()
analyzeSDDraft 方法会在过渡服务之前分析服务定义草稿。 该方法可以返回许多错误和警告,例如缺少元数据、将数据复制到服务器或参数不兼容。
在成功运行 exportToSDDraft 方法后使用此方法。 如果没有生成服务定义草稿文件,则尝试使用此方法时将会出错。
返回值
| 数据类型 | 说明 |
|---|---|
|
Dictionary |
包含分析器错误和警告的字典。 字典中的错误和警告都将以元组列表的形式提供,如果存在元组,那么每个元组中都有分析器代码和分析器消息。 如果没有错误或警告,则字典中的 |
以下是 analyzeSDDraft 函数的返回示例,显示无分析器错误,但有一个分析器警告:
{
'errors': [],
'warnings': [
(24032, 'Data source used by CustomizedModel is not registered with the server and will be copied to the server: raster_data')
],
'messages': []
}
exportToSDDraft(out_sddraft)
将 GeoprocessingSharingDraft 转换为服务定义草稿文件 (.sddraft)。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_sddraft |
A string that represents the path and file name for the output service definition draft file ( |
String |
代码示例
以下脚本可使用关键字参数创建一个 GeoprocessingSharingDraft 对象。 当脚本运行完成时,会将一个 Web 工具发布到 ArcGIS Enterprise。 由于工具的输入参数是要素图层,Web 工具参数的 输入模式 是选项列表,因此会发出有关复制到联合 ArcGIS Server 的数据的分析器警告。
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://organization.example.com/webadaptorname",
"MyUsername", "MyPassword")
# Set output file names
outdir = r"C:\Project"
service_name = "GeoprocessingSharingDraftExample"
federated_server_url = "https://gisserver.example.com/webadaptor"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
# Run the tool and set the history to a result object
arcpy.ImportToolbox(os.path.join(outdir, "MyAnalysisTools.atbx"))
result = arcpy.reports.MyCustomAnalysis(os.path.join(outdir, "parcels.gdb", "taxlots"), "40", "MyOutput.pdf")
# Create GeoprocessingSharingDraft using keyword arguments
sddraft = arcpy.sharing.GeoprocessingSharingDraft(serverType="FEDERATED_SERVER", serviceType="WEB_TOOL",
serviceName=service_name, draftValue=[result], targetServer=federated_server_url,
GPStringValues=["Input_Areal_Unit"])
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Get the analyzer messages
analyzer_results = sddraft.analyzeSDDraft()
if len(analyzer_results["errors"]) > 0:
# Display the analyzer error or processing error messages
for code, message in analyzer_results["errors"]:
print(message)
# Raise an exception and exit the script
raise arcpy.ExecuteError
# Display the analyzer warning messages using the analyze function
for code, message in analyzer_results["warnings"]:
print(message)
# Run Stage Service tool
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Share to portal
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
以下脚本可以创建 Web 工具服务定义草稿文件 (.sddraft)。 然后,系统会将服务定义草稿文件过渡并作为 Web 工具发布到 ArcGIS Enterprise。 由于工具的第一个工具输入参数是要素类,因此 Web 工具参数的 输入模式 为 用户定义 。
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://organization.example.com/webadaptorname",
"MyUsername", "MyPassword")
# Set output file names
outdir = r"C:\Project"
service_name = "GeoprocessingSharingDraftExample"
federated_server_url = "https://gisserver.example.com/webadaptor"
toolbox = os.path.join(outdir, "MyAnalysisTools.tbx")
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
# Run the tool and set to a result object
arcpy.ImportToolbox(toolbox)
result = arcpy.reports.MyCustomAnalysis(os.path.join(outdir, "parcels.gdb", "taxlots"), "40", "MyOutput.pdf")
# Create GeoprocessingSharingDraft and set its properties
sddraft = arcpy.sharing.CreateSharingDraft("FEDERATED_SERVER", "WEB_TOOL", service_name, result)
sddraft.targetServer = federated_server_url
sddraft.description = "This is description"
sddraft.summary = "This is summary"
sddraft.tags = "tag1, tag2"
sddraft.serverFolder = "MyServerFolder"
sddraft.portalFolder = "MyPortalFolder"
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
try:
# Run Stage Service tool
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Display the analyzer warning messages
print(arcpy.GetMessages(1))
# Share to portal
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
except arcpy.ExecuteError:
# Display the analyzer error or processing error messages
print(arcpy.GetMessages(2))
以下脚本可以覆盖 Web 工具服务定义草稿文件 (.sddraft)。 如果服务名称已存在,则将覆盖该 web 工具。 否则,将创建新 web 工具。 由于第一个工具输入参数是图层,而 GeoprocessingSharingDraft 类的 choiceLists 参数包含两个图层,web 工具参数的 输入模式 为包含两个图层的 选项列表 。
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://organization.example.com/webadaptorname",
"MyUsername", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "GeoprocessingSharingDraftExample"
federated_server_url = "https://gisserver.example.com/webadaptor"
toolbox = os.path.join(outdir, "MyAnalysisTools.tbx")
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
# Run the tool and set to a result object
arcpy.management.MakeFeatureLayer(os.path.join(outdir, "parcels.gdb", "taxlots1"), "taxlotslayer1")
arcpy.management.MakeFeatureLayer(os.path.join(outdir, "parcels.gdb", "taxlots2"), "taxlotslayer2")
arcpy.ImportToolbox(toolbox)
result = arcpy.reports.MyCustomAnalysis("taxlotslayer1", "40", "MyOutput.pdf")
# Create GeoprocessingSharingDraft and set overwrite and choicelists properties
sddraft = arcpy.sharing.CreateSharingDraft("FEDERATED_SERVER", "WEB_TOOL", service_name, result)
sddraft.targetServer = federated_server_url
sddraft.description = "This is description"
sddraft.summary = "This is summary"
sddraft.tags = "tag1, tag2"
sddraft.serverFolder = "MyServerFolder"
sddraft.portalFolder = "MyPortalFolder"
sddraft.overwriteExistingService = True
sddraft.choicelists = {"mywebtooltask.parameter1": ["taxlotslayer1", "taxlotslayer2"]}
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
try:
# Run Stage Service tool
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Display the analyzer warning messages
print(arcpy.GetMessages(1))
# Share to portal
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
except arcpy.ExecuteError:
# Display the analyzer error or processing error messages
print(arcpy.GetMessages(2))
以下脚本将为目标门户版本创建 离线服务定义 ,并将其发布为 Web 工具。
import arcpy
import os
# Set output file names
outdir = r"C:\Project\Output"
service_name = "GeoprocessingSharingDraftExample"
toolbox = os.path.join(outdir, "MyAnalysisTools.tbx")
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
# Run the tool and set to a result object
arcpy.ImportToolbox(toolbox)
result = arcpy.reports.MyCustomAnalysis(os.path.join(outdir, "parcels.gdb", "taxlots"), "50", "MyOutput.pdf")
# Create GeoprocessingSharingDraft and set offline and offlineTarget properties
server_type = "FEDERATED_SERVER"
sddraft = arcpy.sharing.CreateSharingDraft("FEDERATED_SERVER", "WEB_TOOL", service_name, result)
sddraft.offline = True
# Set offlineTarget property to "11" for ArcGIS Enterprise 11.0 or later
# The default is ArcGIS Enterprise 10.9.1 or earlier
sddraft.offlineTarget = "10x"
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Run Stage Service tool
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Sign in to portal to upload and publish
arcpy.SignInToPortal("https://organization.example.com/webadaptorname",
"MyUserName", "MyPassword")
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, server_type)
print("Finish Publishing")
以下脚本将创建地理处理服务的服务定义草稿文件 (.sddraft)。 然后,系统会将脚本服务定义草稿文件过渡并作为 地理处理服务 发布到 ArcGIS Server。 由于工具的第一个工具输入参数是要素类,地理处理参数的 输入模式 为 用户定义 。
import arcpy
import os
# Set output file names
outdir = r"C:\Project\Output"
service_name = "GeoprocessingSharingDraftExample"
toolbox = os.path.join(outdir, "MyAnalysisTools.tbx")
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
# Run the tool and set to a result object
arcpy.ImportToolbox(toolbox)
result = arcpy.reports.MyCustomAnalysis(os.path.join(outdir, "parcels.gdb", "taxlots"), "40", "MyOutput.pdf")
# Create GeoprocessingSharingDraft
target_server_connection = os.path.join(outdir, "gp_publisher_conn.ags")
sddraft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "GP_SERVICE", service_name, result)
sddraft.targetServer = target_server_connection
sddraft.description = "This is description"
sddraft.summary = "This is summary"
sddraft.tags = "tag1, tag2"
sddraft.serverFolder = "MyServerFolder"
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
try:
# Run Stage Service tool
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Display the analyzer warning messages
print(arcpy.GetMessages(1))
# Publish to stand-alone server
arcpy.server.UploadServiceDefinition(sd_output_filename, target_server_connection)
except arcpy.ExecuteError:
# Display the analyzer error or processing error messages
print(arcpy.GetMessages(2))