当前位置:   article > 正文

arcgis10.0及以上版本,使用arcpy加载在arctoolbox中批量添加同一图层_arctoolbox输入图层

arctoolbox输入图层


代码:

  1. #coding=gbk
  2. #author:杨勇
  3. #qq:1874445373
  4. #'''此脚本会报错,但是会正确的执行添加图层的操作。
  5. #可以添加.lyr .shp geodatabase 唯独不能添加.dwg
  6. import arcpy.mapping as mapping,os,arcpy,random,string
  7. mxd_dir = arcpy.GetParameterAsText(0) #MXD目录
  8. add_layer = arcpy.GetParameterAsText(1) #.lyr目录;eg:c\\yy\\yy.lyr ;cad数据通过另存为lyr进行批量加载
  9. word = 'new_mxd_y'
  10. goal_path = os.path.join(mxd_dir,word)
  11. x = random.randint(0,10000)
  12. y = str(x)
  13. goal_path_new = os.path.join(goal_path,y)
  14. isExists = os.path.exists(goal_path)
  15. if not isExists:
  16. os.mkdir(goal_path)
  17. else:
  18. os.mkdir(goal_path_new)
  19. for root,dirs,files in os.walk(r"%s"%mxd_dir):
  20. for name in files:
  21. if name[-4:].lower() == '.mxd':
  22. filename = os.path.join(root,name)
  23. mxd =arcpy.mapping.MapDocument(r"%s"%filename)
  24. df = arcpy.mapping.ListDataFrames(mxd)[0]
  25. alayer = arcpy.mapping.Layer(r"%s"%add_layer)
  26. mapping.AddLayer(df,alayer,"AUTO_ARRANGE")
  27. if not isExists:
  28. mxd.saveACopy(os.path.join(goal_path,name))
  29. else:
  30. mxd.saveACopy(os.path.join(goal_path_new,name))

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/310764
推荐阅读
相关标签
  

闽ICP备14008679号