方法
以下の 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 は組織に対して固有であるため、上記の例のスクリプトでは 1 つのフォルダー名のみが印刷されます。 次の例では、アイテムのタイトルを使用してアイテムを検索しています。 アイテム 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 エキスパートのサポートを受ける
今すぐチャットを開始