CreateGeocodeSDDraft

摘要

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

警告:

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

注:

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

说明

要使用 ArcPy 将定位器自动发布到地理编码服务,第一步是 CreateGeocodeSDDraft。 通过 CreateGeocodeSDDraft 创建的输出是服务定义草稿文件 (.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

The catalog path to the locator files (.loc) in a file folder.

String
out_sddraft

The path and file name for the output Service Definition Draft file (.sddraft).

String
service_name

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.

String
server_type

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

  • 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

The path and file name to an ArcGIS Server connection file (.ags).

To publish a geocoding service in ArcGIS Pro, you will need an .ags file that has been created with publisher or administrator credentials for ArcGIS Server 10.6 or later. You can create a connection file using ArcGIS Pro and use the path to that file when publishing in ArcGIS Pro.

String
copy_data_to_server

A Boolean that indicates whether the data referenced in the locator will be copied to the server. The copy_data_to_server parameter is only used if the server_type value is ARCGIS_SERVER and the connection_file_path value is not specified. If the connection_file_path value is specified, the server's registered data stores are used. For example, if the data in the locator is registered with the server, copy_data_to_server will always be False. Conversely, if the data in the locator is not registered with the server, 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

The folder name where the service definition will be published. If the folder does not exist, it will be created when the service definition is published as a service. The default folder is the server root level.

(默认值为 None)

String
summary

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

The Item Description Tags.

Use this parameter to override the user interface tags or to provide tags if they do not exist. To specify multiple tags, separate each tag with a comma in the string.

(默认值为 None)

String
max_result_size

The maximum number of candidates returned by the service when geocoding a single address.

(默认值为 500)

Integer
max_batch_size

The maximum number of records to be processed in each batch job when performing batch geocoding.

(默认值为 1000)

Integer
suggested_batch_size

The recommended number of records to pass in each batch job when performing batch geocoding.

(默认值为 1000)

Integer
supported_operations
[supported_operations,...]

The built-in operations that will be supported by the service. The parameter should be specified as a list containing one or more of the following string keywords:

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

For example, to specify that the service will only support geocoding operations and will not allow reverse geocoding operations, specify the parameter as ["GEOCODE"].

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

String
overwrite_existing_service

Specifies whether an existing service on the server will be overwritten by a new service with the same service_name value. If the service_name value is unique, this parameter is not applicable.

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:
        # Execute StageService to convert sddraft file to a service definition 
        # (sd) file 
        arcpy.server.StageService(sddraft_file, sd_file)

        # Execute 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 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"

# 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:
        # Execute StageService to convert sddraft file to a service definition 
        # (sd) file 
        arcpy.server.StageService(sddraft_file, sd_file)

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

相关主题