CÓMO
Utilice los scripts de Python que se indican a continuación para buscar el nombre de carpeta de un elemento determinado en Portal for ArcGIS.
En el siguiente ejemplo, el Id. de elemento se utiliza para encontrar el elemento y devolver el nombre de su carpeta:
#libraries
import arcgis
from arcgis.gis import GIS
from arcgis.gis import User
#variables
portalurl = "https://hostname.domain.com/portal"
username = "....."
password = "....."
#the id of the item that you want to know is in which folder
#(you can retrieve the item in any other way you find suitable)
itemid = "4f394f2cda81415294f96134220e0c7d"
#login
gis = GIS(portalurl,username,password,verify_cert=False)
#retrieve item
item = gis.content.get(itemid)
#specify user
user = User(gis,username)
#retrieve the folder of the item by searching for the item id
for f in user.folders:
list = user.items(folder=f)
for i in list:
search_id = list[list.index(i)].id
if item.id == search_id:
print(f['title'])
Los Id. de elemento son exclusivos de la organización, por lo que el script del ejemplo anterior solo imprime un nombre de carpeta. En el siguiente ejemplo, el título del elemento se utiliza para encontrarlo. A diferencia del Id. de elemento, puede haber más de un elemento con el mismo título en la organización, y el siguiente script devuelve todos los elementos con ese título y los nombres de sus carpetas:
#libraries
import arcgis
from arcgis.gis import GIS
from arcgis.gis import User
#variables
portalurl = "https://hostname.domain.com/portal"
username = "........"
password = "........"
#the title of the item that you want to know is in which folder
#(you can retrieve the item in any other way you find suitable)
itemtitle= "..........."
#login
gis = GIS(portalurl,username,password,verify_cert=False)
#retrieve item
itemsearch = gis.content.search(query=f"title:{itemtitle}")
#specify user
user = User(gis,username)
#retrieve the folder of the item by searching for the item title
for f in user.folders:
list = user.items(folder=f)
for i in list:
if i.title == itemtitle:
print(f"{i} is in folder {f['title']}")
Id. de artículo: 000028966
Obtener ayuda de expertos en ArcGIS
Empieza a chatear ahora