操作方法
使用以下的 Python 脚本在 Portal for ArcGIS 中查找给定项目的文件夹名称。
在以下示例中,项目 ID 用于查找项目并返回其文件夹名称:
#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'])
项目 ID 对于组织是唯一的,因此上述示例中的脚本仅打印一个文件夹名称。 在以下示例中,项目标题用于查找项目。 与项目 ID 不同,组织中可以有多个具有相同标题的项目,以下脚本将返回具有该标题及其文件夹名称的所有项目:
#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: 000028966
获取来自 ArcGIS 专家的帮助
立即开始聊天