CreateWebLayerSDDraft

Zusammenfassung

Converts a map, layer, or list of layers in an ArcGIS Project to a Service Definition Draft (.sddraft) file.

Auswertung

Ältere Versionen:
The arcpy.sharing module was introduced at ArcGIS Pro 2.2 to provide a better experience when sharing web layers over the previously existing function CreateWebLayerSDDraft. The original function is provided only for continuing backward compatibility. For more information, see Introduction to the sharing module.

CreateWebLayerSDDraft is the first step to automate the publishing of a map, layer, or list of layers to a hosted web layer using ArcPy. The output created from the CreateWebLayerSDDraft is a Service Definition Draft (.sddraft) file.

To share a web layer, you must have the following:

  • An account that is part of an online organization
  • Membership in a Publisher or Administrator role for your account

The Service Definition Draft can then be converted to a fully consolidated Service Definition (.sd) file using the Stage Service tool. Staging compiles all the necessary information needed to successfully publish the GIS resource. Finally, the Service Definition file can be uploaded and published as a GIS service to a specified online organization 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.

When publishing hosted services to ArcGIS Online, sign-in information is obtained from the user name and password that you were prompted to enter when you started ArcGIS Pro.

Syntax

CreateWebLayerSDDraft (map_or_layers, out_sddraft, service_name, {server_type}, {service_type}, {folder_name}, {overwrite_existing_service}, {copy_data_to_server}, {enable_editing}, {allow_exporting}, {enable_sync}, {summary}, {tags}, {description}, {credits}, {use_limitations})
ParameterErklärungDatentyp
map_or_layers

A variable that references a Map object, Layer object, or a list of Layer objects. If publishing a list of Layer objects, they must be from the same map.

Object
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. Currently, the only supported value is MY_HOSTED_SERVICES for ArcGIS Online.

(Der Standardwert ist MY_HOSTED_SERVICES)

String
service_type

A string representing the service type.

  • FEATURE_ACCESSSupports vector querying, visualization, and editing.
  • TILEDSupports fast map visualization using a collection of predrawn map images or tiles. These tiles are created and stored on the server after you upload your data.
Hinweis:

Map image layers and map services are not supported service types in the CreateWebLayerSDDraft function. Instead, use the arcpy.sharing module.

(Der Standardwert ist FEATURE_ACCESS)

String
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. The default folder is the server root level.

(Der Standardwert ist None)

String
overwrite_existing_service

A Boolean that determines whether to overwrite an existing service or not.

(Der Standardwert ist False)

Boolean
copy_data_to_server

A Boolean that indicates whether the data referenced in the map or layers are copied to the server or not.

(Der Standardwert ist False)

Boolean
enable_editing

A Boolean that determines if editing of feature services is enabled. Query capability is always on. Editing is optional.

(Der Standardwert ist False)

Boolean
allow_exporting

A Boolean that determines if users can export the service to different formats.

(Der Standardwert ist False)

Boolean
enable_sync

A Boolean that determines if users can work with a local copy of the data even when they are offline and synchronize changes when they are online.

(Der Standardwert ist False)

Boolean
summary

A string that represents the summary.

(Der Standardwert ist None)

String
tags

A string that represents the tags. Multiple tags can be added or separated by a comma or semicolon.

(Der Standardwert ist None)

String
description

A string that represents the description.

(Der Standardwert ist None)

String
credits

A string that represents the credits.

(Der Standardwert ist None)

String
use_limitations

A string that represents the use limitations.

(Der Standardwert ist None)

String

Codebeispiel

The following script publishes a map as feature access layers to ArcGIS Online.

import arcpy
aprx = arcpy.mp.ArcGISProject('C:/Project/Counties.aprx')
m = aprx.listMaps('USA Counties')[0]
arcpy.mp.CreateWebLayerSDDraft(m, 'C:/Project/Counties.sddraft', 'Counties', 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS')
arcpy.StageService_server('C:/Project/Counties.sddraft', 'C:/Project/Counties.sd')
arcpy.UploadServiceDefinition_server('C:/Project/Counties.sd', 'My Hosted Services')

The following script publishes a list of layers as tiled layers to ArcGIS Online.

import arcpy
aprx = arcpy.mp.ArcGISProject('C:/Project/Counties.aprx')
m = aprx.listMaps('USA Counties')[0]
lyrs=[]
lyrs.append(m.listLayers('Cities')[0])
lyrs.append(m.listLayers('Counties')[0])
arcpy.mp.CreateWebLayerSDDraft(lyrs, 'C:/Project/Counties.sddraft', 'Counties', 'MY_HOSTED_SERVICES', 'TILED')
arcpy.StageService_server('C:/Project/Counties.sddraft', 'C:/Project/Counties.sd')
arcpy.UploadServiceDefinition_server('C:/Project/Counties.sd', 'My Hosted Services')

The following script publishes a single layer as a feature access layer to ArcGIS Online.

import arcpy
aprx = arcpy.mp.ArcGISProject('C:/Project/Counties.aprx')
m = aprx.listMaps('USA Counties')[0]
lyr = m.listLayers('Cities')[0]
arcpy.mp.CreateWebLayerSDDraft(lyr, 'C:/Project/Cities.sddraft', 'Cities', 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS')
arcpy.StageService_server('C:/Project/Cities.sddraft', 'C:/Project/Cities.sd')
arcpy.UploadServiceDefinition_server('C:/Project/Cities.sd', 'My Hosted Services')