12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- # -*- coding: utf-8 -*-
- import os
- import sys
- import log
- import uuid
- import arcpy
- import arcpy.mapping as mp
- class FzxzMap:
- def __init__(self):
- self.root = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../mxds/fzxz"))
- self.mxd = os.path.join(self.root, r"FzxzMap.mxd");
- self.shp = os.path.join(self.root, r"fzxz.shp");
- arcpy.RefreshActiveView()
- def run(self):
- mxd = mp.MapDocument(self.mxd)
- df = mp.ListDataFrames(mxd)[0]
- layF = mp.ListLayers(mxd, 'fzxzF')[0]
- layM = mp.ListLayers(mxd, 'fzxzM')[0]
- layExtent = layF.getExtent()
- jpgPath = ""
- cursor = arcpy.SearchCursor(layF, ['BSM'])
- for row in cursor:
- bsm = row.getValue("BSM")
- rwbsm = row.getValue("RWBSM")
- if jpgPath == "":
- jpgPath = os.path.join(self.root, "jpgs", rwbsm)
- if os.path.exists(jpgPath) == False:
- os.makedirs(jpgPath)
- where = "BSM='{0}'".format(str(bsm))
- # 全局
- fileF = os.path.join(jpgPath, '{0}_F.jpg'.format(bsm))
- if os.path.exists(fileF) == False:
- layF.definitionQuery = where
- layM.definitionQuery = ''
- df.extent = layExtent
- arcpy.RefreshActiveView()
- arcpy.mapping.ExportToJPEG(mxd, fileF, resolution=90)
- print(fileF)
- # 局部
- fileM = os.path.join(jpgPath, '{0}_M.jpg'.format(bsm))
- if os.path.exists(fileM) == False:
- layF.definitionQuery = '-1'
- layM.definitionQuery = where
- df.extent = layM.getExtent()
- arcpy.RefreshActiveView()
- arcpy.mapping.ExportToJPEG(mxd, fileM, resolution=90)
- print(fileM)
|