FeatureSharingDraft

サマリー

The FeatureSharingDraft class allows you to create a service definition draft file (.sddraft) for a web feature layer that copies all data 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 include a feature layer.

説明

To create the FeatureSharingDraft object, use the Map object's getWebLayerSharingDraft method and set the service_type parameter to FEATURE. The FeatureSharingDraft object can then be configured by setting service level properties and metadata properties.

You can also set web layer properties by modifying the .sddraft file. If no value is specified for a property, the default is set. You must set the appropriate property values even if you are overwriting a web layer that has existing configured properties.

注意:

メタデータのプロパティ (creditsdescriptionsummarytagsuseLimitations) が設定されていないか空の文字列で構成されている場合、Web レイヤー アイテムは、共有されるものに応じてマップまたはレイヤーからメタデータを供給します。 Web レイヤーがメタデータを供給する方法については、「Web レイヤーのメタデータ」をご参照ください。

After the FeatureSharingDraft object is configured, it can be saved to a service definition draft file (.sddraft) using the exportToSDDraft method. 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 What is the arcpy.sharing module.

Code samples are available for the following:

プロパティ

プロパティ説明データ タイプ
allowExporting
(読み書き)

Specifies whether the web layer can be exported to different formats.

Boolean
allowUpdateWithoutMValues
(読み書き)

Specifies whether geometry updates to m-enabled features are allowed without specifying an m-value. The default value is True.

Boolean
approvePublicDataCollection
(読み書き)

Specifies whether public editing on a web feature layer is allowed.

Boolean
checkUniqueIDAssignment
(読み書き)

Specifies whether the map is analyzed to confirm that the Allow assignment of unique numeric IDs for sharing web layers option in Map Properties is enabled. For more information, see Assign layer IDs.

Boolean
credits
(読み書き)

The credits of the web layer.

String
description
(読み書き)

The description of the web layer.

String
featureCapabilities
(読み書き)

The enabled capabilities, separated by commas. The following capabilities are supported:

  • Query
  • Create
  • Update
  • Delete
  • Sync
  • Extract
  • Editing

String
maxRecordCount
(読み書き)

The maximum number of records that will be returned by the server during querying. The default value is 2000.

Integer
offline
(読み書き)

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

Boolean
offlineTarget
(読み書き)

The target portal version to which the service definition will be published. Specifying a version ensures that the service definition contains content compatible with your portal. This property is only honored if the offline property is set to True.

  • ENTERPRISE_10x—Content will be compatible with ArcGIS Enterprise 10.9.1 or earlier. This is the default.
  • ENTERPRISE_11—Content will be compatible with ArcGIS Enterprise 11.0 or later.
  • ONLINE—Content will be compatible with ArcGIS Online.
String
overwriteExistingService
(読み書き)

Specifies whether an existing web layer will be overwritten.

Boolean
portalFolder
(読み書き)

The name of the portal folder where the web layer will be published. The default folder is your root folder in My Content.

String
preserveEditUsersAndTimestamps
(読み書き)

Specifies whether editor tracking information will be preserved. The default value is False.

Boolean
serviceName
(読み書き)

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
sharing.groups
(読み書き)

The group names, separated by commas.

String
sharing.sharingLevel
(読み書き)

The sharing level of the web layer.

  • OWNER - そのアイテムにアクセスできるのは、所有者 (および他のメンバーが所有しているコンテンツを表示する権限のある組織のメンバー) だけです。
  • ORGANIZATION - コンテンツを組織内のすべての認証済みユーザーと共有します。
  • EVERYONE - コンテンツが一般公開されます。 誰もがコンテンツにアクセスして、表示することができます。

String
summary
(読み書き)

The summary of the web layer.

String
tags
(読み書き)

The tags of the web layer. Multiple tags can be added or separated by a comma.

String
useLimitations
(読み書き)

The use limitations of the web layer.

String
serverType
(読み取り専用)

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 FeatureSharingDraft is HOSTING_SERVER. A serverType value of HOSTING_SERVER indicates support for sharing to ArcGIS Enterprise or ArcGIS Online.

String
timezone.ID
(読み書き)

The time zone in which date values are stored. The string value must match one of the official time zone IDs recognized by the Windows operating system. For a list of time zones, see Time zones in the Microsoft documentation.

String
timezone.DaylightSavingTime
(読み書き)

Specifies whether the time zone accounts for daylight saving time. The default value is False.

Boolean
timezone.preferredTimezoneID
(読み書き)

The time zone for ArcGIS Pro to use when displaying queries from the web feature layer. The string value must match one of the official time zone IDs recognized by the Windows operating system. For a list of time zones, see Time zones in the Microsoft documentation..

String
timezone.preferredTimezoneIDDaylightSavingTime
(読み書き)

Specifies whether the preferred time zone accounts for daylight saving time. The default value is False.

Boolean
useCIMSymbols
(読み書き)

Specifies whether Esri Cartographic Information Model (CIM) symbols, also known as ArcGIS Pro symbols, will be used. Set to False to use symbols that can be rendered by all clients. Set to True to use CIM symbols supported by newer clients such as ArcGIS API for JavaScript 4.x.

This property is only honored if the service definition is published to ArcGIS Online or ArcGIS Enterprise 11.3 or later.

Boolean
zDefault.enable
(読み書き)

Specifies whether editors will be allowed to add or update features through clients that don't allow a z-value to be given. The default value is True.

Boolean
zDefault.value
(読み書き)

The default z-value when inserting or updating features. This property is only honored if the zDefault.enable property is set to True. The default value is 0.

Double

方法の概要

方法説明
exportToSDDraft (out_sddraft)

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

方法

exportToSDDraft (out_sddraft)
パラメーター説明データ タイプ
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.

コードのサンプル

Publish a web feature layer to a portal folder

The following script creates a web feature layer service definition draft file (.sddraft) for a map and sets metadata, export data properties, and CIM symbols. The web feature layer is published to a folder in either ArcGIS Online or ArcGIS Enterprise and shared with everyone (public). 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, export data properties, and CIM symbols
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.featureCapabilities = "Extract"
sddraft.useCIMSymbols = True
sddraft.sharing.sharingLevel = "EVERYONE"
sddraft.sharing.groups = ""  # Group names = "group1,group2"

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

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

# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(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. If you want the web layer to have specific properties, you must set property values even if the web layer being overwritten already has properties configured. Otherwise, the existing properties will be overwritten with default settings.

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.server.StageService(sddraft_output_filename, sd_output_filename)

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

print("Finish Publishing")
Set create and sync capabilities

The following script creates a web feature layer service definition draft file (.sddraft) and sets the create and sync capabilities on the web feature layer. The .sddraft file is then staged and published to a portal.

import arcpy
import os

# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
                     "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
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.featureCapabilities = "Create,Sync,Query"

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

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

# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(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('States')[0]
selected_table = m.listTables('Capitals')[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.server.StageService(sddraft_output_filename, sd_output_filename)

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

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

The following script creates an offline service definition for the target portal version 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 and offlineTarget properties
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.offline = True
# Set offlineTarget property to "ONLINE" for ArcGIS Online or "ENTERPRISE_11" for ArcGIS Enterprise 11.0 or later
# The default is ArcGIS Enterprise 10.9.1 or earlier
sddraft.offlineTarget = "ENTERPRISE_10x"

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

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

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

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

print("Finish Publishing")
Analyze to confirm map is set to allow assignment of unique numeric IDs

The following script creates a web feature layer service definition draft file (.sddraft) that enables the checkUniqueIDAssignment property. The .sddraft file is analyzed during staging. If the map is not set to allow assignment of unique numeric IDs for sharing web layers, analyzer error 00374 is returned and a message is printed. For more information, see Assign layer IDs.

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 the check unique ID assignment property
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name)
sddraft.checkUniqueIDAssignment = True

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

try:
    # Stage Service
    print("Start Staging")
    arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
    # Share to portal
    print("Start Uploading")
    arcpy.server.UploadServiceDefinition(sd_output_filename, server_type)

    print("Finish Publishing")
except Exception as stage_exception:
    if "00374" in str(stage_exception):
        print("The map is not set to allow assignment of unique IDs")
    print("Analyzer errors encountered - {}".format(str(stage_exception)))

except arcpy.ExecuteError:
    print(arcpy.GetMessages(2))
Publish a table using field types compatible with earlier ArcGIS Pro releases

The following script sets the useCompatibleFieldTypes property from the env class, adds a table to a map, and publishes a hosted table to ArcGIS Enterprise.

import arcpy
import os

# Set useCompatibleFieldTypes property
arcpy.env.useCompatibleFieldTypes = True

data = r"C:\states.csv"

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

# Open existing project, create a map with a basemap, and add data
aprx = arcpy.mp.ArcGISProject(os.path.join(outdir, r"C:\Project\World.aprx"))
m = aprx.createMap(service_name, "Map")
m.addBasemap("Topographic")
m.addDataFromPath(data)
print(f"Data added: {data}")
aprx.save()
print(f"Project saved: {aprx.filePath}")

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

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

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

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

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

print("Finish Publishing")

関連トピック