操作方法

操作方法:使用 ArcGIS API for Python 将具有存储凭据的 Web 图层添加到 ArcGIS Online

Last Published: January 13, 2025

描述

可以使用 gis.content.add() 函数通过 ArcGIS API for Python 将 Web 图层从现有 ArcGIS REST 服务目录添加到 ArcGIS Online。 但是,如果所需图层包含存储的凭据,则功能会受到阻碍,并且添加 Web 图层的过程将失败。

解决方案或解决方法

以下步骤介绍了如何使用 ArcGIS API for Python 将具有存储凭据的 Web 图层添加到 ArcGIS Online。

  1. 导入所需的模块。
from arcgis.map import Map
from arcgis.gis import GIS
  1. 连接到 ArcGIS Online 账户并创建令牌。
gis = GIS('https://www.arcgis.com','username')

token = gis._con.token
  1. 为所需的 Web 图层创建项目属性。 项目属性指定访问 Web 图层所需的凭据。
item_properties = 
{
"title":"TestAdd2", #the same title

"tags":"test",
"url":"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer",

"type":"Feature Service",
"description":"Test Me",
"serviceUsername":"username",
"servicePassword":"password",
"token":token
}
  1. 添加 Web 图层。
gis.content.add(data="https://sample.arcgisonline.com/",owner="username",item_properties=item_properties)

以下为完整代码:

from arcgis.map import Map
from arcgis.gis import GIS

gis = GIS('https://www.arcgis.com','arch0000')

token = gis._con.token

item_properties = 
{
"title":"TestAdd2", #the same title

"tags":"test",
"url":"https://sample.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer",

"type":"Feature Service",
"description":"Test Me",
"serviceUsername":"username",
"servicePassword":"password",
"token":token
}

gis.content.add(data="https://sample.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer",owner="username",item_properties=item_properties)

文章 ID: 000022504

接收通知并查找新问题或常见问题的解决方案

从我们全新的 AI 聊天机器人中获得简明答案和视频解决方案。

下载 Esri 支持应用程序

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项