Skip To Content

CreateWebLayerSDDraft

Summary

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

Discussion

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})
ParameterExplanationData Type
map_or_layers

A variable that references a Mapobject, 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.

(The default value is MY_HOSTED_SERVICES)

String
service_type

A string representing the service type.

  • FEATURE_ACCESSFEATURE_ACCESS supports vector querying, visualization, and editing.
  • TILEDTILED supports 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.
Note:

Currently, map image layer is not a supported service type.

(The default value is 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.

(The default value is None)

String
overwrite_existing_service

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

(The default value is True)

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.

(The default value is False)

Boolean
enable_editing

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

(The default value is False)

Boolean
allow_exporting

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

(The default value is 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.

(The default value is False)

Boolean
summary

A string that represents the summary.

(The default value is None)

String
tags

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

(The default value is None)

String
description

A string that represents the description.

(The default value is None)

String
credits

A string that represents the credits.

(The default value is None)

String
use_limitations

A string that represents the use limitations.

(The default value is None)

String

Code sample

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')