当前位置:网站首页>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
边栏推荐
- Never use redis expired monitoring to implement scheduled tasks!
- New specification of risc-v chip architecture
- 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
- D中不用GC
- 从Celsius到三箭:加密百亿巨头们的多米诺,史诗级流动性的枯竭
- Common operation and Principle Exploration of stream
- Stream常用操作以及原理探索
- Is expression of D
- Niuke challenge 48 e speed instant forwarding (tree over tree)
- [path of system analyst] Chapter 15 double disk database system (database case analysis)
猜你喜欢

Never use redis expired monitoring to implement scheduled tasks!

数学建模经验分享:国赛美赛对比/选题参考/常用技巧

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

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

Jianzhi offer 43.47.46.48 dynamic planning (medium)

array

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

Common operation and Principle Exploration of stream

Gartner 2022年顶级战略技术趋势报告

ArcGIS cannot be opened and displays' because afcore cannot be found ' DLL, solution to 'unable to execute code'
随机推荐
Online bull Blogger
H5关闭当前页面,包括微信浏览器(附源码)
9項規定6個嚴禁!教育部、應急管理部聯合印發《校外培訓機構消防安全管理九項規定》
团队管理的最关键因素
STM32F1和GD32F1有什么区别?
Wechat applet - bind and prevent event bubble catch
Exercises under insect STL string
windows版MySQL软件的安装与卸载
Memory considerations under bug memory management
Server create virtual environment run code
On insect classes and objects
Bug STL string
When drawing with origin, capital letter C will appear in the upper left corner of the chart. The removal method is as follows:
Recent important news
Zero basics of C language lesson 8: Functions
Range of types
虫子 STL string 下 练习题
8.Ribbon负载均衡服务调用
How to check if a text field is empty or not in swift
The most critical elements of team management