CreateGeocodeSDDraft
汇总
CreateGeocodeSDDraft 函数用于将定位器转换为服务定义草稿文件 (.sddraft),以供创建用于发布地理编码服务的服务定义。
注意:
服务定义草稿文件必须先转换为服务定义文件 (.sd),之后才能用于发布到 ArcGIS Server。
注:
草稿服务定义不包含数据。 草稿服务不能单独用于发布服务。
讨论
此函数是使用 ArcPy 自动将定位器发布到地理编码服务的第一步。 此函数可创建一个服务定义草稿文件 (.sddraft),该文件是定位器属性、服务器相关信息和服务属性的组合。
所有地理编码服务都需要定位器。 定位器是 ArcGIS 中进行地理编码的主要工具,其中包含执行地址匹配所需的所有数据。 在 ArcGIS Pro 中,使用 创建定位器 或 创建要素定位器 工具创建定位器。 有关创建定位器的说明,请参阅 创建定位器 或 创建要素定位器 。 用于将多个定位器合为一体的复合定位器也可以发布到 ArcGIS Server。 有关详细信息,请参阅 将多个定位器组合成复合定位器 。
服务器信息包括服务器连接、发布到的服务器的类型、服务的元数据(项目信息)和数据参考(是否将数据复制到服务器)。
服务属性包括服务支持的地理编码和反向地理编码等操作、对单个地址进行地理编码时服务返回的最大候选项数量,或者执行地理编码批处理时在每个批处理作业中处理的最大记录数。
注:
无法使用此函数来设置服务的池化属性,例如每台计算机的最大或最小实例数。 改为先发布 .sddraft 文件,然后通过使用 XML 库(例如 xml.dom.minidom )对 .sddraft 文件进行编辑来修改草稿。
此函数会返回字典,其中包含应在创建服务定义文件之前解决的错误和其他潜在问题。
可在特定服务器连接信息未知的情况下编写服务定义草稿文件。 在这种情况下,可以忽略 connection_file_path 参数;但是,必须提供 server_type 值。 可在使用 上传服务定义 工具发布服务定义草稿文件后提供服务器连接。
随后可使用 过渡服务 工具将服务定义草稿文件转换为完全合并的服务定义文件 (.sd)。 过渡过程会编译成功发布 GIS 资源所需的所有必要信息。 如果未将数据注册到服务器,将在过渡服务定义草稿文件时添加这些数据。 可以使用 上传服务定义 工具上传服务定义文件并将其作为 GIS 服务发布到指定 GIS 服务器。 此步骤将获取服务定义文件,并将其复制到服务器,提取所需信息并发布 GIS 资源。 有关详细信息,请参阅 发布工具集概述 。
语法
CreateGeocodeSDDraft(loc_path, out_sddraft, service_name, {server_type}, {connection_file_path}, {copy_data_to_server}, {folder_name}, {summary}, {tags}, {max_result_size}, {max_batch_size}, {suggested_batch_size}, {supported_operations}, {overwrite_existing_service})
| 参数 | 说明 | 数据类型 |
|---|---|---|
|
loc_path |
文件夹中定位器文件 ( |
String |
|
out_sddraft |
输出 |
String |
|
service_name |
服务的名称。 用户可以看到该名称并使用该名称来识别服务。 名称只能包含字母数字字符和下划线。 不允许使用空格或特殊字符。 名称不能超过 120 个字符。 |
String |
|
server_type |
指定服务器类型。 如果未为
(默认值为 ARCGIS_SERVER) |
String |
|
connection_file_path |
ArcGIS Server 连接文件 ( 要在 ArcGIS Pro 中发布地理编码服务,需要之前使用 ArcGIS Server 10.6 或更高版本的使用发布者或管理员凭据创建的 |
String |
|
copy_data_to_server |
指定是否将定位器中引用的数据复制到服务器。 仅当
(默认值为 False) |
Boolean |
|
folder_name |
将发布服务定义的文件夹名称。 如果文件夹不存在,则将在服务定义发布为服务时创建文件夹。 默认的文件夹为服务器根级别。 (默认值为 None) |
String |
|
summary |
项目描述摘要文本。 使用此参数可以覆盖用户界面摘要,如果摘要不存在,则将提供摘要。 (默认值为 None) |
String |
|
tags |
项目描述标签文本。 使用此参数可以覆盖用户界面标签,如果标签不存在,则将提供标签。 要指定多个标签,请在字符串中以逗号分隔各标签。 (默认值为 None) |
String |
|
max_result_size |
地理编码单个地址时服务将返回的最大候选项数。 (默认值为 500) |
Integer |
|
max_batch_size |
执行批量地理编码时每次批处理作业将处理的最大记录数。 (默认值为 1000) |
Integer |
|
suggested_batch_size |
执行批量地理编码时每次批处理作业将通过的记录的建议数量。 (默认值为 1000) |
Integer |
|
supported_operations |
指定服务将支持的内置操作。 应将此参数值指定为包含一个或多个下列字符串关键字的列表:
例如,如果希望仅支持地理编码操作,请使用 (默认值为 ["GEOCODE", "REVERSE_GEOCODE", "SUGGEST"]) |
String |
|
overwrite_existing_service |
指定服务器上的现有服务是否将被具有相同 |
Boolean |
返回值
| 数据类型 | 说明 |
|---|---|
|
Dictionary |
由信息性消息、警告和错误组成的字典。 |
代码示例
以下脚本演示了在仅支持查找地址、反向地理编码和返回建议的独立服务器上,将地址定位器发布为地理编码服务的完整工作流。 无法使用此服务对表进行地理编码。 发布工作流中的第一步是使用 CreateGeocodeSDDraft 函数基于地址定位器创建服务定义草稿文件 (.sddraft)。 然后,使用 StageService 函数基于服务定义草稿文件创建服务定义文件 (.sd)。 最后,使用 UploadServiceDefinition 函数将服务定义文件作为服务发布到 GIS 服务器。
如果已经存在地理编码服务,请将 overwrite_existing_service 参数设置为 True ,以便成功发布该服务。 如果要使用数据存储发布定位器,请将 copy_data_to_server 参数设置为 False 。
import arcpy
import pprint
# Overwrite any existing outputs
arcpy.env.overwriteOutput = True
locator_path = "C:\\Data\\Locators\\Atlanta"
sddraft_file = "C:\\Output\\Atlanta.sddraft"
sd_file = "C:\\Output\\Atlanta.sd"
service_name = "Atlanta"
summary = "Address locator for the city of Atlanta"
tags = "address, locator, geocode"
# Create an AGS connection file to your standalone server
# in ArcGIS Pro
gis_server_connection_file = "C:\\Data\\server_connection"
# Specify the supported operations for the service based on the version
# of server the locator will be published to.
supported_operations = ["FIND_ADDRESS_CANDIDATES", "REVERSE_GEOCODE", "SUGGEST"]
# Create the sd draft file
analyze_messages = arcpy.CreateGeocodeSDDraft(
locator_path, sddraft_file, service_name,
connection_file_path=gis_server_connection_file, copy_data_to_server=True,
summary=summary, tags=tags, max_result_size=20, max_batch_size=500,
suggested_batch_size=150, supported_operations=supported_operations,
overwrite_existing_service=False)
# Stage and upload the service if the sddraft analysis did not contain errors.
if analyze_messages['errors'] == {}:
try:
# Run StageService to convert sddraft file to a service definition
# (sd) file
arcpy.server.StageService(sddraft_file, sd_file)
# Run UploadServiceDefinition to publish the service definition
# file as a service.
arcpy.server.UploadServiceDefinition(sd_file, gis_server_connection_file)
print("The geocode service was successfully published")
except arcpy.ExecuteError:
print("An error occurred")
print(arcpy.GetMessages(2))
else:
# If the sddraft analysis contained errors, display them.
print("Error were returned when creating service definition draft")
pprint.pprint(analyze_messages['errors'], indent=2)
以下脚本演示了在仅支持地理搜索查找地址、反向地理编码和返回建议的 ArcGIS Enterprise 上,将地址定位器发布为地理编码服务的完整工作流。 无法使用此服务进行批量地理编码。 发布工作流中的第一步是使用 CreateGeocodeSDDraft 函数基于地址定位器创建服务定义草稿文件 (.sddraft)。 然后,使用 StageService 函数基于服务定义草稿文件创建服务定义文件 (.sd)。 最后,使用 UploadServiceDefinition 函数将服务定义文件作为服务发布到 GIS 服务器。
如果已经存在地理编码服务,请将 overwrite_existing_service 参数设置为 True ,以便成功发布该服务。 如果要使用数据存储发布定位器,请将 copy_data_to_server 参数设置为 False 。
注:
如果您正在使用您的门户上的定位器,请确保您已登录系统并在 ArcGIS Pro 中将其设置为您的活动门户。 要访问除活动门户之外的门户上的定位器,您可以使用 SignInToPortal 进行身份验证:
import arcpy
import pprint
# Overwrite any existing outputs
arcpy.env.overwriteOutput = True
locator_path = "C:\\Data\\Locators\\Atlanta"
sddraft_file = "C:\\Output\\Atlanta.sddraft"
sd_file = "C:\\Output\\Atlanta.sd"
service_name = "Atlanta"
summary = "Address locator for the city of Atlanta"
tags = "address, locator, geocode"
# The URL of the federated server you are publishing to.
in_server = "https://machinename.domainname.com/server"
# Specify the supported operations for the service based on the version
# of ArcGIS Enterprise the locator is shared to.
supported_operations = ["FIND_ADDRESS_CANDIDATES", "REVERSE_GEOCODE", "SUGGEST"]
# Create the sd draft file
analyze_messages = arcpy.CreateGeocodeSDDraft(
locator_path, sddraft_file, service_name, copy_data_to_server=True,
summary=summary, tags=tags, max_result_size=20, max_batch_size=500,
suggested_batch_size=150, supported_operations=supported_operations,
overwrite_existing_service=False)
# Stage and upload the service if the sddraft analysis did not contain errors
if analyze_messages['errors'] == {}:
try:
# Run StageService to convert sddraft file to a service definition
# (sd) file.
arcpy.server.StageService(sddraft_file, sd_file)
# Run UploadServiceDefinition to publish the service definition
# file as a service.
arcpy.server.UploadServiceDefinition(sd_file, in_server)
print("The geocode service was successfully published")
except arcpy.ExecuteError:
print("An error occurred")
print(arcpy.GetMessages(2))
else:
# If the sddraft analysis contained errors, display them.
print("Error were returned when creating service definition draft")
pprint.pprint(analyze_messages['errors'], indent=2)