exportToSDDraft
汇总
TileSharingDraft 类允许您为 web 切片图层 创建服务定义草稿文件 (.sddraft),该文件将所有数据复制到 ArcGIS Enterprise 或 ArcGIS Online。
讨论
要创建 TileSharingDraft 对象,使用 Map 对象的 getWebLayerSharingDraft 方法并将 service_type 参数设置为 TILE 。 随后即可通过设置服务级别属性和元数据属性来配置 TileSharingDraft 对象。
注:
如果未设置元数据属性( credits 、 description 、 summary 、 tags 和 useLimitations )或其具有空字符串,则 Web 图层项目将从地图或图层中获取元数据,具体取决于共享的内容。 有关 Web 图层如何获取元数据的详细信息,请参阅 Web 图层元数据 。
配置 TileSharingDraft 对象后,可以使用 exportToSDDraft 方法将其保存到服务定义草稿文件 (.sddraft)。 随后即可使用 过渡服务 和 上传服务定义 工具将其过渡和共享给 ArcGIS Enterprise 或 ArcGIS Online。 有关详细信息,请参阅 什么是 arcpy.sharing 模块 。
下方代码示例可用于以下用途:
语法
exportToSDDraft()
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
cache.configuration (读取和写入) |
由 生成地图服务器缓存切片方案 工具生成的预定义切片方案 |
String |
|
cache.exportTiles (读取和写入) |
指定是否允许客户端下载地图切片以供离线使用。 默认值为 |
Boolean |
|
cache.exportTilesCount (读取和写入) |
单个请求中可下载的最大切片数量。 仅在属性 |
Integer |
|
credits (读取和写入) |
web 图层制作者名单。 |
String |
|
description (读取和写入) |
web 图层的描述。 |
String |
|
offline (读取和写入) |
指定是否使用门户连接。 如果设置为 |
Boolean |
|
offlineTarget (读取和写入) |
将发布服务定义的目标门户版本。 指定版本,确保服务定义包含与门户兼容的内容。 仅在属性
|
String |
|
portalFolder (读取和写入) |
将发布 Web 图层的门户文件夹的名称。 默认文件夹是“我的内容”中的根文件夹。 |
String |
|
serverType (只读) |
根据 地图 类中的 |
String |
|
serviceName (读取和写入) |
web 图层名称。 用户可以看到该名称并使用该名称来识别 web 图层。 名称只能包含字母数字字符和下划线。 不允许使用空格或特殊字符。 名称不能超过 120 个字符。 |
String |
|
sharing.groups (读取和写入) |
以逗号分隔的组名称。 |
String |
|
sharing.sharingLevel (读取和写入) |
Web 图层的共享级别。
|
String |
|
summary (读取和写入) |
Web 图层的摘要。 |
String |
|
tags (读取和写入) |
Web 图层的标签。 可以添加多个标签,或用逗号分隔。 |
String |
|
useLimitations (读取和写入) |
Web 图层的使用限制。 |
String |
方法
exportToSDDraft(out_sddraft)
将 TileSharingDraft 转换为服务定义草稿 (.sddraft) 文件。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_sddraft |
用于表示输出服务定义草稿 ( |
String |
代码示例
以下脚本将为地图创建 Web 切片图层 服务定义草稿文件 (.sddraft),并设置元数据属性。 Web 切片图层将发布到 ArcGIS Enterprise 或 ArcGIS Online 的文件夹中并与所有人(公共)共享。 门户信息可从 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 = "TileSharingDraftExample"
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 TileSharingDraft and set metadata and portal folder properties
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "TILE", 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.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")
result = arcpy.server.UploadServiceDefinition(sd_output_filename, server_type)
value_table_op = arcpy.ValueTable(2)
value_table_op.loadFromString(result[11])
for i in range(0, value_table_op.rowCount):
print(value_table_op.getRow(i))
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 = "TileSharingDraftExample"
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 TileSharingDraft and set tiling scheme, export tile, and export tile count properties
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "TILE", service_name)
sddraft.cache.configuration = r"C:\Program Files\ArcGIS\Pro\Resources\TilingSchemes\ArcGIS_Online_Bing_Maps_Google_Maps.xml"
sddraft.cache.exportTiles = True
sddraft.cache.exportTilesCount = 5566
# 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")
results = arcpy.server.UploadServiceDefinition(sd_output_filename, server_type)
rest_url = results[6]
# Manage Map Server Cache Tiles
# For cache, use multiple scales separated by semicolon (;)
# For example, "591657527.591555;295828763.795777"
arcpy.server.ManageMapServerCacheTiles(rest_url, "591657527.591555", "RECREATE_ALL_TILES")
print("Finish publishing")
下面的脚本将图层的列表从地图作为 Web 切片图层 发布到 ArcGIS Enterprise,且该图层具有可选的指定项目 ID。 门户信息可从 SignInToPortal 函数中获得。
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://organization.example.com/webadaptorname",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "TileSharingDraftExample"
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]
lyrs = []
lyrs.append(m.listLayers('Cities')[0])
lyrs.append(m.listLayers('Counties')[0])
# Create TileSharingDraft and set metadata properties
sharing_draft = m.getWebLayerSharingDraft("HOSTING_SERVER", "TILE", service_name, lyrs)
sharing_draft.summary = "My Summary"
sharing_draft.tags = "My Tags"
sharing_draft.description = "My Description"
sharing_draft.credits = "My Credits"
sharing_draft.useLimitations = "My Use Limitations"
# Create Service Definition Draft file
sharing_draft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Replace "itemid" with desired item ID
item_id = "web_tile_layer_id itemid"
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, "My Hosted Services", in_item_id=item_id)
print("Finish Publishing")
以下脚本将为目标门户版本创建 离线服务定义 ,并将其发布为 Web 切片图层。
import arcpy
import os
# Set output file names
outdir = r"C:\Project\Output"
service_name = "TileSharingDraftExample"
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 TileSharingDraft and set offline and offlineTarget properties
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "TILE", 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://organization.example.com/webadaptorname",
"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")