当前位置:网站首页>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
边栏推荐
- Formal parameters vs actual parameters
- Jianzhi offer 43.47.46.48 dynamic planning (medium)
- Niuke challenge 48 e speed instant forwarding (tree over tree)
- 虫子 类和对象 上
- GC is not used in D
- Wechat applet SetData dynamic variable value sorting
- FreeFileSync 文件夹比较与同步软件
- 9项规定6个严禁!教育部、应急管理部联合印发《校外培训机构消防安全管理九项规定》
- 虫子 STL string 下 练习题
- Setup instance of layout manager login interface
猜你喜欢

hands-on-data-analysis 第三单元 模型搭建和评估

Sword finger offer 15.65.56 I 56Ⅱ. Bit operation (simple - medium)

How to call self written functions in MATLAB

Generation and rendering of VTK cylinder

Eigen(3):error: ‘Eigen’ has not been declared

Intellij IDEA--格式化SQL文件的方法

Related knowledge of libsvm support vector machine

Sword finger offer 40.41 Sort (medium)

RISC-V 芯片架构新规范

Jianzhi offer 43.47.46.48 dynamic planning (medium)
随机推荐
Sword finger offer 40.41 Sort (medium)
How to check if a text field is empty or not in swift
MySQL | basic commands
Sword finger offer 18.22.25.52 Double pointer (simple)
Research on balloon problem
Obtain information about hard disk and volume or partition (capacity, ID, volume label name, etc.)
程序员必备,一款让你提高工作效率N倍的神器uTools
Cloudcompare - Poisson reconstruction
Hands on data analysis unit 3 model building and evaluation
DOS command
从Celsius到三箭:加密百亿巨头们的多米诺,史诗级流动性的枯竭
Niuke challenge 53:c. strange magic array
Wechat applet Registration Guide
Gartner 2022 Top Strategic Technology Trends Report
Pytorch based generation countermeasure Network Practice (7) -- using pytorch to build SGAN (semi supervised GaN) to generate handwritten digits and classify them
PHP非对称加密算法(RSA)加密机制设计
Common operation and Principle Exploration of stream
Pychar remotely connects to the server to run code
D中不用GC
Bug memory management