羣組是GIS中的協作空間,用戶可在其中分享內容。羣組支持元數據,並允許你根據其主題來自定義。你可以在羣衆創建用戶並分配給其相關的羣組權限。
在gis
模塊中,Group
類表示羣組。與Items
、Users
和Roles
一樣,GroupManager
的實例對象用來創建、查詢和賦予權限給Group
對象,可通過GIS
對象的groups
來獲取其實例對象。
查詢羣組
可以使用search()
方法來查詢羣組。search()
方法接收標準的ArcGIS REST API
的查詢參數。
from arcgis.gis import GIS
gis = GIS(url="https://singlega.jiaoxn.local/arcgis", username="esricd", password="12345678", verify_cert=False)
all_groups = gis.groups.search()
all_groups
from arcgis.gis import GIS
gis = GIS(url="https://singlega.jiaoxn.local/arcgis", username="esricd", password="12345678", verify_cert=False)
all_groups = gis.groups.search(query='owner:esri and description:basemaps', max_groups=15)
all_groups
羣組的屬性
在Python中可以使用dir(<object>)
查詢羣組實例的屬性,Group羣組實例的常用的屬性有:
id
access
owner
created
groupid
isFav
創建羣組
通過Python API,可調用GroupManager
示例的create()
方法來創建新的羣組。和其他ResourcesManager
實例的create()
方法一樣,該方法會返回一個Group
對象。
from arcgis.gis import GIS
gis = GIS(url="https://singlega.jiaoxn.local/arcgis", username="esricd", password="12345678", verify_cert=False)
new_group = gis.groups.create(title='Recreational geocaching',
tags = 'hobby, geocaching, gps, hide n seek',
description = 'Group to share your landmarks and games',
snippet = 'Share your GPX tracks as feature layers here',
access = 'org',
is_invitation_only = 'False',
thumbnail = r'../../static/img/geocaching.jpeg')
分享內容到羣組
在一個ArcGIS組織中,一個內容項可以設置特定的訪問權限:private
、group
、org
和everyone
。當被分享到一個羣組時,該羣組內的用戶均可訪問它。
# new_content是新創建的用戶項
new_content.share(groups=new_group)
管理你的羣組
查看羣組的內容項列表
使用Group
羣組對象實例的content()
方法,可以查看當前羣組有權訪問的內容項列表。
my_group.content()
添加用戶到羣組
Python API添加用戶可以有兩種方法:一種是通過使用Group
對象實例的add_user()
方法,同時以列表的方式提供用戶名稱;另一種是通過使用Group
對象實例的invite_users()
方法邀請用戶加入這個羣組。
my_group.add_users([]"api_data_owner")
# 返回
{
"notAdded": []
}
該方法將會返回哪些用戶沒有被成功添加到羣組。
查看羣組中的用戶
使用Group
羣組對象實例的get_members()
方法,查看當前羣組中的用戶列表。
my_group.get_members()
該方法不僅會返回羣組中的用戶列表,並且會將這些用戶分類到owner
、admins
和users
這三個類別中。返回示例:
{
"owner": "arcgis_python",
"admins": ["arcgis_python"],
"users": ["api_data_owner"]
}
更新羣組
使用Group
對象實例的update()
方法可以更新羣組,通過該函數,可以更新創建羣組時提供的任意一個羣組字段,這也意味着更新羣組的參數和創建羣組的參數是一致的。
my_group.update(is_invitation_only=True)
終止羣組
當一個羣組已經完成了其服務的目標或者其需求已經改變了,羣組管理員和羣組成員可以有幾種選擇。他們可以通過leave()
方法離開羣組。當一個用戶離開羣組時,其分享的內容會自動的被取消當前羣組的分享。羣組的所有者或者管理員可通過delete()
方法來刪除羣組。
當羣組和羣組的內容必須得保留,可通過ressign_to()
更改羣組的所有者並制定新的用戶名。這一塊需要注意的是,只有組織的管理員才能夠更改羣組的所有者。
# 更改羣組的所有者
geocaching_group.reassign_to(target_owner = 'api_data_owner')
# 刪除羣組
geocaching_group.delete()