操作方法
压缩文件地理数据库 (FGDB) 中的项目可能具有有限的数据备份功能。 通过将数据存储在数据库中,可以更方便地查看数据。 通过使用 ArcGIS API for Python 将 ArcGIS Online 项目备份至数据库连接,可以同时下载、提取和复制多个项目。
from arcgis.gis import GIS import arcpy import os import zipfile import glob import shutil arcpy.env.overwriteOutput = True
gis=GIS("https://arcgis.com","username","password") folders = [] root = r"Path To Location Where AGOL Items are Downloaded" items = ['ItemID1', 'ID2', 'ID3', 'ID4'] destination = r"Path To Location Where Downloaded zipped folders are extracted" outputPath = r"Full File Path to SDE Connection\<connectionname>.sde"
#the variable 'items' can be replaced to get all items in ArcGIS Online if the need is to back up all items for item in items: test = gis.content.get(item) fgdb_title = test.title fgdb_title=fgdb_title.replace('_', '') result = test.export(fgdb, "File Geodatabase") result.download(root) result.delete() folders.append(root +'\\' +fgdb_title + '.zip') print(folders)
for folder in folders: with zipfile.ZipFile(folder) as zf: folder.replace('_','') zf.extractall(destination)
注: 仅当运行脚本时由于现有文件而出现错误时,才需要执行步骤 5 以移除本地文件。
for FGDB in FGDBlist: item_delete = (destination+FGDB+'\\') #Removes FGDBs in Destination folder(optional) shutil.rmtree(item_delete)
FGDBlist=os.listdir(destination) for FGDB in FGDBlist: gdb_var=(destination+FGDB+'\\') arcpy.env.workspace=(gdb_var) featureclasses = arcpy.ListFeatureClasses() print(featureclasses) for FC in featureclasses: rename = arcpy.Rename_management(FC, FC + "_copy", "FeatureClass") print(rename) arcpy.FeatureClassToFeatureClass_conversion(gdb_var + FC + "_copy", outputPath, FC + "_copy")
获取来自 ArcGIS 专家的帮助
下载 Esri 支持应用程序