当前位置:网站首页>ArcGIS secondary development method - layer related operations (add, modify)
ArcGIS secondary development method - layer related operations (add, modify)
2022-06-26 14:22:00 【Chaoying.】
import arcpy
import os
waveHs = os.listdir('./tifs1')
waveHs = filter(lambda waveH: waveH.endswith('.tif'), waveHs)
waveCs = os.listdir('./contours1')
waveCs = filter(lambda waveC: waveC.endswith('.shp'), waveCs)
waves = zip(waveHs, waveCs)
tifpath = r'C:\Users\user\Desktop\SeaGIS\tifs1'
shppath = r'C:\Users\user\Desktop\SeaGIS\contours1'
n = 0
mxd = arcpy.mapping.MapDocument(r'C:\Users\user\Desktop\SeaGIS\MXD\Template.mxd')
for tif, shp in waves:
print [tif, shp]
tiflay = arcpy.mapping.Layer(r'C:\Users\user\Desktop\SeaGIS\MXD\Hs.lyr')
shplay = arcpy.mapping.Layer(r'C:\Users\user\Desktop\SeaGIS\MXD\Contour.lyr')
tiflay.replaceDataSource(tifpath, 'RASTER_WORKSPACE', tif[0:-4], True)
tiflay.name = tif[0:-4]
shplay.replaceDataSource(shppath, 'SHAPEFILE_WORKSPACE', shp[0:-4], True)
# shplay.replaceDataSource(shppath, 'SHAPEFILE_WORKSPACE', shp, False)
shplay.name = shp[0:-4]
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.mapping.AddLayer(df, tiflay)
arcpy.mapping.AddLayer(df, shplay)
n += 1
if n == 24:
end = int(tif[0:-4])
start = end - 23 * 3600
mxdname = str(start) + '_' + str(end) + '.mxd'
mxd.saveACopy(r'C:\Users\user\Desktop\SeaGIS\MXD\{}'.format(mxdname))
print r'C:\Users\user\Desktop\SeaGIS\MXD\{} has beed created!'.format(mxdname)
del mxd
mxd = arcpy.mapping.MapDocument(r'C:\Users\user\Desktop\SeaGIS\MXD\Template.mxd')
n = 0
print 'ok!'
Key points : Replace layer data source ,dataset_name The parameter only needs the file name , No file suffix is required , Otherwise you may report an error , And it is better to write a complete absolute path for the workspace path
边栏推荐
- Linear basis count (k large XOR sum)
- Pychar remotely connects to the server to run code
- Pointer
- Formal parameters vs actual parameters
- Sword finger offer 45.61 Sort (simple)
- 7.Consul服务注册与发现
- Hard (magnetic) disk (I)
- Global variable vs local variable
- Zero basics of C language lesson 8: Functions
- 数学建模经验分享:国赛美赛对比/选题参考/常用技巧
猜你喜欢

Use performance to see what the browser is doing

Win10 home vs pro vs enterprise vs enterprise LTSC

Sword finger offer 05.58 Ⅱ string

8. Ribbon load balancing service call

Freefilesync folder comparison and synchronization software

Zero basics of C language lesson 7: break & continue

Sword finger offer 10 Ⅰ 10Ⅱ. 63 dynamic planning (simple)

9 regulations and 6 prohibitions! The Ministry of education and the emergency management department jointly issued the nine provisions on fire safety management of off campus training institutions

Never use redis expired monitoring to implement scheduled tasks!

量化框架backtrader之一文读懂observer观测器
随机推荐
Sword finger offer 40.41 Sort (medium)
ThreadLocal giant pit! Memory leaks are just Pediatrics
Sword finger offer 45.61 Sort (simple)
Mathematical design D12 according to string function
Common controls and custom controls
9项规定6个严禁!教育部、应急管理部联合印发《校外培训机构消防安全管理九项规定》
Postman自动化接口测试
Logical operation
8. Ribbon load balancing service call
Memory considerations under bug memory management
Usage of unique function
Self created notes (unique in the whole network, continuously updated)
Hands on data analysis unit 3 model building and evaluation
Server create virtual environment run code
Luogu p4513 xiaobaiguang Park
Build your own PE manually from winpe of ADK
Bug memory management
How to convert data in cell cell into data in matrix
CVPR 2022文档图像分析与识别相关论文26篇汇集简介
Never use redis expired monitoring to implement scheduled tasks!