CreateGeocodeSDDraft (arcpy)
摘要
此函数将地址定位器转换为服务定义草稿 (.sddraft) 文件,该文件可创建用于发布地理编码服务的服务定义。
草稿服务定义不包含数据。草稿服务不能单独用于发布服务。
讨论
CreateGeocodeSDDraft 是使用 ArcPy 将地址定位器自动发布到地理编码服务的第一步。通过 CreateGeocodeSDDraft 创建的输出是服务定义草稿 (.sddraft) 文件。服务定义草稿由地址定位器属性、服务器信息和一组服务属性组合而成。
所有地理编码服务都需要地址定位器。地址定位器是 ArcGIS 中进行地理编码的主要工具,该工具包含了执行地址匹配所需的所有数据。可使用 ArcCatalog、ArcGIS for Desktop 中的目录 窗口或创建地址定位器地理处理工具来创建地址定位器。有关详细的分步说明,请参阅 ArcGIS 帮助中的创建地址定位器。将多个定位器合为一体的复合定位器也可发布到 ArcGIS Server。有关详细信息,请参阅创建复合地址定位器。
服务器信息包括服务器连接、发布到的服务器的类型、服务的元数据(项目信息)和数据参考(是否将数据复制到服务器)。
服务属性包括服务支持的地理编码和反向地理编码等操作、对单个地址进行地理编码时服务返回的最大候选项数量,或者执行地理编码批处理时每个批处理作业中处理的最大记录数。
服务的池化属性(例如每台计算机的最大或最小实例数)不会作为函数的参数显示。如果需要修改值(或其他任何未显示的参数),您需要先发布 sddraft,然后通过使用 XML 库(例如 xml.dom.minidom)编辑此 .sddraft 来修改此草稿。有关库的用法,请参阅 sddraft 修改示例。尽管示例来自地图服务草稿,但可以对地理编码服务草稿使用同一个库和方法,因为它是一个 XML 文件。
此函数会返回字典,其中包含应在创建服务定义文件之前解决的错误和其他潜在问题。
可在特定服务器连接信息未知的情况下编写服务定义草稿。在这种情况下,可以省略 connection_file_path 参数;但是,必须提供 server_type。可在使用上载服务定义工具发布服务定义草稿后提供服务器连接。
随后可使用过渡服务工具将服务定义草稿转换为完全合并的服务定义 (.sd) 文件。过渡过程会编译成功发布 GIS 资源所需的所有必要信息。如果未将数据注册到服务器,将在过渡服务定义草稿时添加这些数据。最后,可以使用上载服务定义工具上载服务定义文件并将其作为 GIS 服务发布到特定的 GIS 服务器。此步骤将获取服务定义文件、将其复制到服务器、提取所需信息并发布 GIS 资源。有关详细信息,请参阅发布工具集概述。
语法
参数 | 说明 | 数据类型 |
loc_path | A string that represents the catalog path to the address locator. Valid formats for the address locator are locator files (.loc) in a file folder or locators in a geodatabase. | 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_SERVER) | String |
connection_file_path |
A string that represents the path and file name to the ArcGIS for Server connection file (.ags). A new connection file can be created using the CreateGISServerConnectionFile function. | String |
copy_data_to_server |
A Boolean that indicates whether the data referenced in the address locator 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 data in the address locator is registered with the server, then copy_data_to_server will always be False. Conversely, if the data in the address locator is not registered with the server, then copy_data_to_server will always be True. (默认值为 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 when the service definition is published as a service. 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. To specify multiple tags, separate each tag with a comma within the string. (默认值为 None) | String |
max_candidates | 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 supported by the service. The parameter should be specified as a list containing one or more of the following string keywords:
For example, to specify that the service should only support geocoding operations and should not allow any reverse geocoding operations, the parameter should be specified as ["GEOCODE"]. (默认值为 [GEOCODE, REVERSE_GEOCODE]) | List |
数据类型 | 说明 |
Dictionary |
返回由信息性消息、警告和错误组成的字典。 |
代码实例
下列脚本演示将地址定位器发布为地理编码服务的完整工作流。发布工作流中的第一步是使用 CreateGeocodeSDDraft 函数基于地址定位器创建服务定义草稿文件 (.sddraft)。然后,使用 StageService 函数基于服务定义草稿文件创建服务定义文件 (.sd)。最后,使用 UploadServiceDefinition 函数将服务定义文件作为服务发布到 GIS 服务器。
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"
gis_server_connection_file = "C:\\Data\\server_connection.ags"
#Create the sd draft file
analyze_messages = arcpy.CreateGeocodeSDDraft(locator_path, sddraft_file, service_name,
connection_file_path=gis_server_connection_file,
summary=summary, tags=tags, max_result_size=20,
max_batch_size=500, suggested_batch_size=150)
#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 as ex:
print "An error occured"
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)