操作方法

操作方法:将内容从一个 ArcGIS Online 组织或 Portal for ArcGIS 复制/克隆到另一个组织或 Portal for ArcGIS

摘要

通常认为 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 中的管理员。
  1. 导入所需的模块。
from arcgis.gis import GIS
  1. 指定原始 ArcGIS Online 帐户的 URL 和凭据。
#对于 ArcGIS Online gis=GIS("https://arcgis.com", "Username", "Password") #对于 Portal for ArcGIS gis=GIS("https://<gisserver>.<domain>.com/portal", "Username", "Password")
  1. 指定帐户的用户名以导出克隆的项目。
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)
  1. 创建要克隆的项目的列表。 要执行此操作,有多个选项可供使用:
  • 设置要导出的最大项目数:
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')
  • 使用项目 ID 获取指定项目:
itemid = '<item_ID>' #insert the item id items = gis.content.get(itemid)
  • 使用带有查询的 Search 函数以搜索要克隆的特定项目。 常规格式如下:
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)
  1. 打印要克隆的项目列表。
print(str(len(items)) + " items will be cloned. See the list below:") items
  1. 创建逻辑以使用 clone_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 支持应用程序

转至下载选项

相关信息

发现关于本主题的更多内容