先上代码
import arcpy
import os
if __name__ == "__main__":
tifdir = r'I:\DInSAR\PJQZ\result'
shpdir = r'I:\DInSAR\reference'
tifs = []
with open("./filter_list.txt", mode='r') as f:
tifs = f.readlines()
tifs = [tif.strip() for tif in tifs]
mxd = arcpy.mapping.MapDocument("template.mxd")
player = arcpy.mapping.ListLayers(mxd, wildcard='Reference Point')[0]
rlayer = arcpy.mapping.ListLayers(mxd, wildcard='DInSAR deformation value')[0]
datetxt = arcpy.mapping.ListLayoutElements(mxd, element_type="TEXT_ELEMENT", wildcard='TITLE')[0]
hightxt = arcpy.mapping.ListLayoutElements(mxd, element_type="TEXT_ELEMENT", wildcard='HIGH')[0]
lowtxt = arcpy.mapping.ListLayoutElements(mxd, element_type="TEXT_ELEMENT", wildcard='LOW')[0]
for tif in tifs:
tifpath = os.path.join(tifdir, tif)
raster = arcpy.Raster(tifpath)
maxvalue = raster.maximum
minvalue = raster.minimum
maxvalue = format(maxvalue * 100, "0.1f")
minvalue = format(minvalue * 100, "0.1f")
arcpy.mapping.Layer.replaceDataSource(player, shpdir, workspace_type='SHAPEFILE_WORKSPACE',
dataset_name='{}.shp'.format(tif[0:-4]), validate=True
)
arcpy.mapping.Layer.replaceDataSource(rlayer, tifdir, workspace_type='RASTER_WORKSPACE',
dataset_name=tif, validate=True)
datetxt.text = tif[0:-4]
hightxt.text = 'High : {} cm'.format(maxvalue)
lowtxt.text = 'Low : {} cm'.format(minvalue)
arcpy.mapping.ExportToPNG(mxd, "./png/{}.png".format(tif[0:-4]), "PAGE_LAYOUT", resolution=384)
arcpy.mapping.MapDocument.saveACopy(mxd, "./mxd/{}.mxd".format(tif[0:-4]))
print "{} ok!".format(tif)
结果输出