FeatureSharingDraft

Summary

The FeatureSharingDraft class allows you to configure the properties of a web feature layer that copies all data and create a service definition draft (.sddraft) file, which can be shared to either ArcGIS Enterprise or ArcGIS Online. To configure the properties of a web feature layer that references registered data, modify the MapImageSharingDraft class to enable feature access.

Discussion

To create the FeatureSharingDraft class object, use the map class function getWebLayerSharingDraft and set the service_type parameter to FEATURE. The FeatureSharingDraft class object can then be configured by setting service level properties. After the FeatureSharingDraft class object has been configured, it can be saved to a service definition draft (.sddraft) file using the exportToSDDraft function. It can then be staged and shared to either ArcGIS Enterprise or ArcGIS Online using the Stage Service and Upload Service Definition tools. For more information, see Introduction to arcpy.sharing.

Code samples are available for the following:

Properties

PropertyExplanationData Type
allowExporting
(Read and Write)

A Boolean that determines whether users can export the web layer to different formats.

Boolean
credits
(Read and Write)

A string that represents the credits.

String
description
(Read and Write)

A string that represents the description.

String
offline
(Read and Write)

A Boolean that determines whether to use a portal connection. If offline is set to False, you must be signed in to a portal to create a service definition draft (.sddraft) file using the exportToSDDraft function. If offline is set to True, a service definition draft file can be created without being signed in to a portal.

Boolean
overwriteExistingService
(Read and Write)

A Boolean that determines whether to overwrite an existing web layer.

Boolean
portalFolder
(Read and Write)

A string that represents the name of a portal folder to which you want to publish the web layer. The default folder is your root folder in My Content.

String
serverType
(Read Only)

Returns a string representing the server type as specified when the sharing draft was created from the getWebLayerSharingDraft function from the map class. The only possible value returned from serverType for a FeatureSharingDraft is HOSTING_SERVER. A serverType of HOSTING_SERVER indicates support for sharing to ArcGIS Enterprise or ArcGIS Online.

String
serviceName
(Read and Write)

A string that represents the name of the web layer. This is the name people will see and use to identify the web layer. 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
summary
(Read and Write)

A string that represents the summary.

String
tags
(Read and Write)

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

String
useLimitations
(Read and Write)

A string that represents the use limitations.

String

Method Overview

MethodExplanation
exportToSDDraft (out_sddraft)

Converts a FeatureSharingDraft to a service definition draft (.sddraft) file.

Methods

exportToSDDraft (out_sddraft)
ParameterExplanationData Type
out_sddraft

A string that represents the path and file name for the output service definition draft (.sddraft) file.

String

Once the FeatureSharingDraft has been configured, it can then be saved as a service definition draft (.sddraft) file. It can then be staged and shared to either ArcGIS Enterprise or ArcGIS Online using the Stage Service and Upload Service Definition tools.

Code sample

Publish a web feature layer

The following script creates a web feature layer service definition draft (.sddraft) file for a map and sets metadata and export data properties. The web feature layer is published to a folder in either ArcGIS Online or ArcGIS Enterprise. Portal information is obtained from the SignInToPortal function.

import arcpy
import os

# Sign in to portal
arcpy.SignInToPortal("https://www.arcgis.com", "MyUserName", "MyPassword")

# Set output file names
outdir = r"C:\Project\Output"
service_name = "FeatureSharingDraftExample"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)

# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]

# Create FeatureSharingDraft and set metadata, portal folder, and export data properties
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.credits = "These are credits"
sddraft.description = "This is description"
sddraft.summary = "This is summary"
sddraft.tags = "tag1, tag2"
sddraft.useLimitations = "These are use limitations"
sddraft.portalFolder = "my folder name"
sddraft.allowExporting = True

# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)

# Stage Service
print("Start Staging")
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Start Uploading")
arcpy.UploadServiceDefinition_server(sd_output_filename, server_type)

print("Finish Publishing")
Overwrite a web feature layer

The following script overwrites a web feature layer. If the service name already exists, the service will be overwritten. Otherwise, a new service will be created.

import arcpy
import os

# Sign in to portal
arcpy.SignInToPortal("https://www.arcgis.com", "MyUserName", "MyPassword")

# Set output file names
outdir = r"C:\Project\Output"
service_name = "FeatureSharingDraftExample"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)

# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]

# Create FeatureSharingDraft and set overwrite property
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.overwriteExistingService = True

# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)

# Stage Service
print("Start Staging")
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Start Uploading")
arcpy.UploadServiceDefinition_server(sd_output_filename, server_type)

print("Finish Publishing")
Publish a layer and table

The following script publishes a layer and table in a map as a web feature layer to a portal.

import arcpy
import os

# Sign in to portal
arcpy.SignInToPortal("https://www.arcgis.com", "MyUserName", "MyPassword")

# Set output file names
outdir = r"C:\Project\Output"
service_name = "FeatureSharingDraftExample"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)

# Reference layers to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
selected_layer = m.listLayers()[0]
selected_table = m.listTables()[0]

# Create FeatureSharingDraft
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name, [selected_layer, selected_table])

# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)

# Stage Service
print("Start Staging")
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Start Uploading")
arcpy.UploadServiceDefinition_server(sd_output_filename, server_type)

print("Finish Publishing")
Create and publish an offline service definition

The following script creates an offline service definition and publishes it as a web feature layer.

import arcpy
import os

# Set output file names
outdir = r"C:\Project\Output"
service_name = "FeatureSharingDraftExample"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)

# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]

# Create FeatureSharingDraft and set offline property
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.offline = True

# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)

# Sign in to portal to upload and publish
arcpy.SignInToPortal("https://www.portal.domain.com/webadaptor", 
"MyUserName", "MyPassword")

# Stage Service
print("Start Staging")
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Start Uploading")
arcpy.UploadServiceDefinition_server(sd_output_filename, server_type)

print("Finish Publishing")