CreateGeocodeSDDraft

摘要

将定位器转换为服务定义草稿文件 (.sddraft),以供创建用于发布地理编码服务的服务定义。

警告:

服务定义草稿文件必须先转换为服务定义文件 (.sd),之后才能用于发布到 ArcGIS Server

注:

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

说明

此函数是使用 ArcPy 自动将定位器发布到地理编码服务的第一步。 该函数可创建一个服务定义草稿文件 (.sddraft),该文件是定位器属性、服务器相关信息和服务属性的组合。

所有地理编码服务都需要定位器。 定位器是 ArcGIS 中进行地理编码的主要工具,其中包含执行地址匹配所需的所有数据。 在 ArcGIS AllSource 中,使用创建定位器创建要素定位器工具创建定位器。 有关创建定位器的说明,请参阅创建定位器创建要素定位器。 用于将多个定位器合为一体的复合定位器也可以发布到 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

文件夹中定位器文件 (.loc) 的目录路径。

String
out_sddraft

输出服务定义草稿文件 (.sddraft) 的路径和文件名。

String
service_name

服务的名称。 用户可以看到该名称并使用该名称来识别服务。 名称只能包含字母数字字符和下划线。 不允许使用空格或特殊字符。 名称不能超过 120 个字符。

String
server_type

服务器类型。 如果未提供 connection_file_path 参数值,则必须提供 server_type 值。 如果提供了 connection_file_path 参数值,则可从连接文件获取 server_type 值。 在这种情况下,您可以选择 FROM_CONNECTION_FILE 或完全跳过该参数。

  • ARCGIS_SERVERThe ArcGIS Server server type.
  • FROM_CONNECTION_FILEGet the server_type value as specified by the connection_file_path parameter.

(默认值为 ARCGIS_SERVER)

String
connection_file_path

ArcGIS Server 连接文件 (.ags) 的路径和文件名。

要在 ArcGIS AllSource 中发布地理编码服务,需要之前使用 ArcGIS Server 10.6 或更高版本的使用发布者或管理员凭据创建的 .ags 文件。 您可以使用 ArcGIS AllSource 创建连接文件,并于在 ArcGIS AllSource 中发布时使用该文件的路径。

String
copy_data_to_server

指定是否将定位器中引用的数据复制到服务器。 仅当 server_type 值为 ARCGIS_SERVER 且未指定 connection_file_path 值时,才使用 copy_data_to_server 参数。 如果 connection_file_path 值已指定,则会使用服务器的已注册数据存储。 例如,如果定位器中的数据已注册到服务器,则 copy_data_to_server 将始终为 False。 相反,如果定位器中的数据未注册到服务器,则 copy_data_to_server 将始终为 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

将发布服务定义的文件夹名称。 如果文件夹不存在,则将在服务定义发布为服务时创建文件夹。 默认的文件夹为服务器根级别。

(默认值为 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
[supported_operations,...]

服务将支持的内置操作。 应将参数指定为包含一个或多个下列字符串关键字的列表:

  • GEOCODE—The service will allow geocoding operations.
  • REVERSE_GEOCODE—The service will allow reverse geocoding operations.
  • SUGGEST—The service will allow suggest operations.

例如,要指定服务将仅支持地理编码操作而不允许反向地理编码操作,请将参数指定为 ["GEOCODE"]

(默认值为 [GEOCODE, REVERSE_GEOCODE, SUGGEST])

String
overwrite_existing_service

指定服务器上的现有服务是否将被具有相同 service_name 值的新服务覆盖。 如果 service_name 值唯一,则此参数不适用。

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"

# 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, 
                        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

以下脚本演示了在 ArcGIS Enterprise 上将地址定位器发布为地理编码服务的完整工作流。 发布工作流中的第一步是使用 CreateGeocodeSDDraft 函数基于地址定位器创建服务定义草稿文件 (.sddraft)。 然后,使用 StageService 函数基于服务定义草稿文件创建服务定义文件 (.sd)。 最后,使用 UploadServiceDefinition 函数将服务定义文件作为服务发布到 GIS 服务器。

如果已经存在地理编码服务,请将 overwrite_existing_service 参数设置为 True,以便成功发布该服务。 如果要使用数据存储发布定位器,请将 copy_data_to_server 参数设置为 False

注:
如果您正在使用您的门户上的定位器,请确保您已登录系统并在 ArcGIS AllSource 中将其设置为您的活动门户。 要访问除活动门户之外的门户上的定位器,您可以使用 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"

# 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, 
                        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)

相关主题