fzxzmap.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import sys
  4. import log
  5. import uuid
  6. import arcpy
  7. import arcpy.mapping as mp
  8. class FzxzMap:
  9. def __init__(self):
  10. self.root = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../mxds/fzxz"))
  11. self.mxd = os.path.join(self.root, r"FzxzMap.mxd");
  12. self.shp = os.path.join(self.root, r"fzxz.shp");
  13. arcpy.RefreshActiveView()
  14. def run(self):
  15. mxd = mp.MapDocument(self.mxd)
  16. df = mp.ListDataFrames(mxd)[0]
  17. layF = mp.ListLayers(mxd, 'fzxzF')[0]
  18. layM = mp.ListLayers(mxd, 'fzxzM')[0]
  19. layExtent = layF.getExtent()
  20. jpgPath = ""
  21. cursor = arcpy.SearchCursor(layF, ['BSM'])
  22. for row in cursor:
  23. bsm = row.getValue("BSM")
  24. rwbsm = row.getValue("RWBSM")
  25. if jpgPath == "":
  26. jpgPath = os.path.join(self.root, "jpgs", rwbsm)
  27. if os.path.exists(jpgPath) == False:
  28. os.makedirs(jpgPath)
  29. where = "BSM='{0}'".format(str(bsm))
  30. # 全局
  31. fileF = os.path.join(jpgPath, '{0}_F.jpg'.format(bsm))
  32. if os.path.exists(fileF) == False:
  33. layF.definitionQuery = where
  34. layM.definitionQuery = ''
  35. df.extent = layExtent
  36. arcpy.RefreshActiveView()
  37. arcpy.mapping.ExportToJPEG(mxd, fileF, resolution=90)
  38. print(fileF)
  39. # 局部
  40. fileM = os.path.join(jpgPath, '{0}_M.jpg'.format(bsm))
  41. if os.path.exists(fileM) == False:
  42. layF.definitionQuery = '-1'
  43. layM.definitionQuery = where
  44. df.extent = layM.getExtent()
  45. arcpy.RefreshActiveView()
  46. arcpy.mapping.ExportToJPEG(mxd, fileM, resolution=90)
  47. print(fileM)