サマリー
The function converts an address locator into a Service Definition Draft (.sddraft) file, which can be used to create a service definition for publishing a geocode service.
説明
CreateGeocodeSDDraft is the first step to automating the publishing of an address locator to a geocode service using ArcPy. The output created from the CreateGeocodeSDDraft is a Service Definition Draft (.sddraft) file. A Service Definition Draft is the combination of address locator properties, information about the server, and a set of service properties.
All geocode services require an address locator. The address locator is the main tool for geocoding in ArcGIS and contains all the data necessary to perform address matching. You can use ArcCatalog, the Catalog window in ArcGIS Desktop, or the Create Address Locator geoprocessing tool to create an address locator. For step-by-step instructions, refer to Creating an address locator in the ArcGIS Help. Composite locators, which combine many locators into one, can also be published to ArcGIS Server. For more information, see Creating a composite address locator.
Information about the server includes the server connection, server type being published to, metadata for the service (Item info), and data references (whether or not data is being copied to the server).
Service properties include operations such as geocoding and reverse geocoding supported by the service, maximum number of candidates returned by the service when geocoding a single address, or the maximum number of records to be processed in each batch job when performing batch geocoding.
The function returns a dictionary containing errors and other potential issues that you should address prior to creating your Service Definition file.
A Service Definition Draft file can be authored without knowing the specific server connection information. In this case, the connection_file_path parameter may be omitted; however, the server_typemust be provided. A server connection can be provided later when the Service Definition Draft file is published using the Upload Service Definition tool.
The Service Definition Draft file can then be converted to a fully consolidated Service Definition (.sd) file using the Stage Servicetool. Staging compiles all the necessary information needed to successfully publish the GIS resource. If your data is not registered with the server, the data will be added when the Service Definition Draft file is staged. Finally, the Service Definition file can be uploaded and published as a GIS service to a specified GIS server using the Upload Service Definition tool. This step takes the Service Definition file, copies it onto the server, extracts required information, and publishes the GIS resource. For more information, see the An overview of the Publishing toolset.
構文
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})
パラメーター | 説明 | データ タイプ |
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 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_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 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, SUGGEST]) | List |
戻り値
データ タイプ | 説明 |
Dictionary | Returns a dictionary of information messages, warnings, and errors. |
コードのサンプル
Publishing a geocode service
The following script demonstrates the complete workflow to publish an address locator as a geocode service. The first step in the publishing workflow is to create a service definition draft file (.sddraft) from the address locator using the CreateGeocodeSDDraft function. The next step is to create a service definition file (.sd) from the service definition draft file using the StageService function. The final step is to publish the service definition file as a service to a GIS server using the UploadServiceDefinition function.
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)