FeatureSharingDraft

摘要

FeatureSharingDraft 类允许您配置复制所有数据的 Web 要素图层的属性,并创建可以与 .sddraftArcGIS Enterprise 共享的服务定义草稿 (ArcGIS Online) 文件。 要配置引用注册数据的 Web 要素图层的属性,请修改 MapImageSharingDraft 类以启用要素访问。

说明

要创建 FeatureSharingDraft 类对象,请使用地图类函数 getWebLayerSharingDraft 并将 service_type 参数设置为 FEATURE。 随后即可通过设置服务级别属性来配置 FeatureSharingDraft 类对象。 FeatureSharingDraft 类对象配置完成后,可以使用 exportToSDDraft 函数将其保存到服务定义草稿 (.sddraft) 文件。 随后即可使用过渡服务上传服务定义工具将其过渡和共享给 ArcGIS EnterpriseArcGIS Online。 有关详细信息,请参阅 arcpy.sharing 简介

代码示例可用于以下用途:

属性

属性说明数据类型
allowExporting
(可读写)

决定用户是否可以将 web 图层导出为不同格式的布尔值。

Boolean
credits
(可读写)

用于表示制作者名单的字符串。

String
description
(可读写)

用于表示描述的字符串。

String
offline
(可读写)

决定是否使用门户连接的布尔值。 如果将 offline 设置为 False,则必须登录到门户,以使用 exportToSDDraft 函数创建服务定义草稿 (.sddraft) 文件。 如果将 offline 设置为 True,则无需登录到门户即可创建服务定义草稿文件。

Boolean
overwriteExistingService
(可读写)

决定是否覆盖现有 web 图层的布尔值。

Boolean
portalFolder
(可读写)

表示要将 Web 图层发布到的门户文件夹的名称的字符串。 默认文件夹是“我的内容”中的根文件夹。

String
serverType
(只读)

返回一个字符串,以表示根据地图类中的 getWebLayerSharingDraft 函数创建共享草稿时指定的服务器类型。 从 FeatureSharingDraftserverType 中返回的唯一可能的值为 HOSTING_SERVERHOSTING_SERVERserverType 表示支持共享至 ArcGIS EnterpriseArcGIS Online

String
serviceName
(可读写)

用于表示 web 图层名称的字符串。 用户可以看到该名称并使用该名称来识别 web 图层。 名称只能包含字母数字字符和下划线。 不允许使用空格或特殊字符。 名称不能超过 120 个字符。

String
summary
(可读写)

用于表示摘要的字符串。

String
tags
(可读写)

用于表示标签的字符串。 可以添加多个标签,标签之间用逗号或分号进行分隔。

String
useLimitations
(可读写)

用于表示使用限制的字符串。

String

方法概述

方法说明
exportToSDDraft (out_sddraft)

FeatureSharingDraft 转换为服务定义草稿 (.sddraft) 文件。

方法

exportToSDDraft (out_sddraft)
参数说明数据类型
out_sddraft

用于表示输出服务定义草稿 (.sddraft) 文件的路径和文件名的字符串。

String

FeatureSharingDraft 配置完成后,即可将其作为服务定义草稿 (.sddraft) 文件进行保存。随后即可使用过渡服务上传服务定义工具将其过渡和共享给 ArcGIS EnterpriseArcGIS Online

代码示例

发布 Web 要素图层

以下脚本为地图创建 Web 要素图层服务定义草稿 (.sddraft) 文件,并设置元数据和导出数据属性。 Web 要素图层将发布到 ArcGIS OnlineArcGIS Enterprise 的文件夹中。 门户信息可从 SignInToPortal 函数中获得。

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")
覆盖 Web 要素图层

以下脚本将覆盖 Web 要素图层。 如果服务名称已存在,服务将被覆盖。 否则,将创建新服务。

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")
发布图层和表

以下脚本将地图中的图层和表作为 Web 要素图层发布至门户。

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")
创建和发布离线服务定义

以下脚本将创建一个离线服务定义,并将其发布为 Web 要素图层。

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