操作方法
通常认为 ArcGIS Online Assistant 是将内容从一个 ArcGIS Online 组织或 Portal for ArcGIS 复制到另一个组织的唯一方法。 但是,以下提供的说明介绍了如何使用 ArcGIS API for Python 来复制 web 地图、可配置应用程序、仪表盘、Shapefile、文件地理数据库等。
以下 Python 脚本(在 Jupyter Notebook 界面中运行)使用 arcgis 模块中的 clone_items 方法将一个 ArcGIS Online 组织中的托管要素图层和基础服务复制到另一个组织。 所用示例单元适用于 Jupyter Notebook,但可以对其进行修改以在独立脚本中使用。
注: 执行复制的用户应该为目标 GIS 中的管理员。
from arcgis.gis import GIS
#对于 ArcGIS Online gis=GIS("https://arcgis.com", "Username", "Password") #对于 Portal for ArcGIS gis=GIS("https://<gisserver>.<domain>.com/portal", "Username", "Password")
username_2 = input("Enter username of target organization: ") #对于 ArcGIS Online gis2 = GIS("https://arcgis.com", username_2) #对于 Portal for ArcGIS gis2 = GIS("https://<gisserver>.<domain>.com/portal", username_2)
num_items = 5 items = gis1.content.search(query="owner: {}".format(username), max_items=num_items, sort_field='id', sort_order='desc')
num_items = int(input("How many items would you like to clone? ")) items = gis1.content.search(query="owner: {}".format(username), max_items=num_items, sort_field='id', sort_order='desc')
itemid = '<item_ID>' #insert the item id items = gis.content.get(itemid)
items = gis.content.search(query, item_type=None, sort_field='avgRating', sort_order='desc', max_items=10, outside_org=False, categories=None, category_filters=None)
print(str(len(items)) + " items will be cloned. See the list below:") items
def deep_copy_content(input_list): for item in input_list: try: print("Cloning " + item.title) copy_list = [] copy_list.append(item) gis2.content.clone_items(copy_list, copy_data=True, search_existing_items=True) print("Successfully cloned " + item.title) except Exception as e: print(e) print("The function has completed") deep_copy_content(items)
注: 另外,如果不需要处理异常,则也可以在逻辑代码块外部使用 clone_items() 函数。 完成步骤 5 后,可以将 clone_items() 函数用作: gis2.content.clone_items([items])
以下显示了完整脚本的示例:
from arcgis.gis import GIS gis=GIS("https://arcgis.com", "Username", "Password") username_2 = input("Enter username of target organization: ") gis2 = GIS("https://arcgis.com", username_2) #Get a specific item using item id: itemid = 'cc94b27a35d14f40987d96f3d2a39e67' items = gis.content.get(itemid) print(str(len(items)) + " items will be cloned. See the list below:") items def deep_copy_content(input_list): for item in input_list: try: print("Cloning " + item.title) copy_list = [] copy_list.append(item) gis2.content.clone_items(copy_list, copy_data=True, search_existing_items=True) print("Successfully cloned " + item.title) except Exception as e: print(e) print("The function has completed") deep_copy_content(items)
文章 ID:000022252
从 ArcGIS 专家处获得帮助
下载 Esri 支持应用程序