概述
import arcpy
mxd = arcpy.mapping.MapDocument('./demo_bak.mxd')
lyrs = arcpy.mapping.ListLayers(mxd)
time = arcpy.mapping.ListLayoutElements(mxd, 'TEXT_ELEMENT', 'time')[0]
for i in range(121):
shp = './shps/{}.shp'.format(i)
cursor = arcpy.SearchCursor(shp, fields='time_str')
row = cursor.next()
time_str = row.getValue('time_str')
del cursor
lyrHs = lyrs[1]
lyrContour = lyrs[0]
lyrHs.replaceDataSource(workspace_path='./tifs/', workspace_type='RASTER_WORKSPACE', dataset_name=i)
lyrContour.replaceDataSource(workspace_path='./contours/', workspace_type='SHAPEFILE_WORKSPACE',
dataset_name=i)
# dataset_name 参数只需要文件名,不需要文件后缀
time.text = time_str
arcpy.mapping.ExportToPNG(mxd, './pngs/{}.png'.format(i), resolution=192)
mxd.saveACopy('./mxds/{}.mxd'.format(i))
print '{}.mxd has been created!'.format(i)
print '{}.png has been created!'.format(i)
del mxd
print 'finished!'
多个图层
import arcpy
times_str = list()
with open('time_str.txt', mode='r') as f:
times_str = f.readlines()
times_str = [time_str.strip() for time_str in times_str]
mxd = arcpy.mapping.MapDocument('./server.mxd')
df = arcpy.mapping.ListDataFrames(mxd)[0]
for i in range(0, 121, 8):
for j in range(i, i + 8):
if j > 120:
j -= 1
break
lyrHs = arcpy.mapping.Layer('./Hs.lyr')
lyrContour = arcpy.mapping.Layer('./Contour.lyr')
lyrHs.replaceDataSource('./tifs/', 'RASTER_WORKSPACE', j)
lyrContour.replaceDataSource('./contours', 'SHAPEFILE_WORKSPACE', j)
lyrContour.showLabels = False
lyrHs.name = times_str[j]
lyrContour.name = times_str[j]
arcpy.mapping.AddLayer(df, lyrHs, 'TOP')
arcpy.mapping.AddLayer(df, lyrContour, 'TOP')
mxdname = times_str[i] + '_' + times_str[j]
mxdname = mxdname.replace(' ', '_')
mxdname = mxdname.replace(':', '-')
mxd.relativePaths = True
mxd.saveACopy('./servers/{}.mxd'.format(mxdname))
print '{}.mxd has been created!'.format(mxdname)
最后
以上就是乐观夕阳为你收集整理的Arcpy自动化批量制图的全部内容,希望文章能够帮你解决Arcpy自动化批量制图所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复