需求:
如何通过arcpy将本地的shp或者gdb中的数据添加到arcmap或者arcgispro中
具体实现:
实现一:arcpy将本地的shp或者gdb中的数据添加到arcmap
arcmap中是python2环境,可以通过下述代码将shp或者gdb中的要素类添加到arcmap的工程文档中(.mxd)
参考这个链接即可:https://blog.csdn.net/gislaozhang/article/details/91447835
实现二:arcpy将本地的shp或者gdb中的数据添加到arcgispro
arcgispro中是python3环境,可以通过下述代码将shp或者gdb中的要素类添加到arcgispro的项目中(.aprx)
import arcpy
aprx = arcpy.mp.ArcGISProject("C:\\Users\\Administrator\\Documents\\ArcGIS\\Projects\\Test\\Test.aprx") #aprx存储路径
aprxMap = aprx.listMaps("Map")[0] #要将数据添加到aprx中的哪个地图下
dataPath="D:\\Template Data\\TemplateData.gdb\\USA\\cities" #数据路径
aprxMap.addDataFromPath(dataPath)
aprx.save()
其中关于save方法的介绍见链接:https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm