当前位置:   article > 正文

arcgis10.0及以上版本,使用arcpy加载在arctoolbox中实现对所有mxd中特定图层的定义查询_arcpy mxd选择图层

arcpy mxd选择图层





代码:

  1. #coding:gbk
  2. #author:yangyong
  3. #会报错,不过不影响正常使用
  4. #cunMing表示村落名称,可用于定义查询,注意用%
  5. import arcpy,os,re
  6. import arcpy.mapping as mapping
  7. global cunMing
  8. import sys
  9. reload(sys)
  10. sys.setdefaultencoding("utf-8")
  11. inputMxdPath = arcpy.GetParameterAsText(0) #floder eg:O:\arcgis_directory\MXD\RHYXT
  12. outputMxdPath = arcpy.GetParameterAsText(1) #floader eg:eg:O:\arcgis_directory\MXD\RHYXT\print
  13. lyrName = arcpy.GetParameterAsText(2) #string eg: XZQ
  14. sqlSentence = arcpy.GetParameter(3) #string eg: [XZQMC] = "%(cunMing)s" (cunMing 会自动替换为具体的村名)
  15. for root,dirs,names in os.walk(r"%s"%inputMxdPath):
  16. for name in names:
  17. if name[-4:].lower() == ".mxd":
  18. a = str('%s')%name
  19. if u"镇" in name:
  20. b = re.split(u"镇",a)[1]
  21. c = re.split(u"村",b)[0]
  22. cunMing = c + "村"
  23. elif "街道" in name:
  24. b = re.split(u"街道", a)[1]
  25. c = re.split(u"村", b)[0]
  26. cunMing = c + "村"
  27. arcpy.AddMessage("%s"%cunMing + "has be Recognition")
  28. mxd = mapping.MapDocument(r"%s"%os.path.join(root,name))
  29. df = mapping.ListDataFrames(mxd,"")[0]
  30. lyrs = arcpy.mapping.ListLayers(mxd,"",df)
  31. for lyr in lyrs:
  32. if lyr.name == "%s"%lyrName:
  33. whereClause = str(sqlSentence)%{"cunMing" : cunMing}
  34. lyr.definitionQuery = whereClause
  35. newName = os.path.join(outputMxdPath,name)
  36. del cunMing
  37. del name,b,c
  38. mxd.saveACopy(r"%s"%newName)

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

闽ICP备14008679号