CÓMO

Agregar una capa web con credenciales almacenadas a ArcGIS Online mediante ArcGIS API for Python

Last Published: January 13, 2025

Descripción

Las capas web se pueden agregar a ArcGIS Online desde un directorio de servicios REST de ArcGIS existente a través de ArcGIS API for Python mediante la función gis.content.add(). Sin embargo, si la capa deseada contiene una credencial almacenada, la función se ve obstaculizada y el proceso de adición de la capa web falla.

Solución o solución alternativa

En los siguientes pasos se describe cómo agregar una capa web con credenciales almacenadas a ArcGIS Online mediante ArcGIS API for Python.

  1. Importe los módulos necesarios.
from arcgis.map import Map
from arcgis.gis import GIS
  1. Conéctese a la cuenta de ArcGIS Online y cree un token.
gis = GIS('https://www.arcgis.com','username')

token = gis._con.token
  1. Cree las propiedades del elemento para la capa web deseada. Las propiedades del elemento especifican las credenciales necesarias para acceder a la capa 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. Agregue la capa web.
gis.content.add(data="https://sample.arcgisonline.com/",owner="username",item_properties=item_properties)

A continuación, se muestra el código completo:

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. de artículo: 000022504

Obtenga soporte con IA

Resuelva su problema rápidamente con el chatbot de inteligencia artificial de soporte de Esri.

Empieza a chatear ahora

Información relacionada

Descubrir más sobre este tema

Obtener ayuda de expertos en ArcGIS

Contactar con el soporte técnico

Empieza a chatear ahora

Ir a opciones de descarga