700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > arcgis中img 批量转换tif_在ArcGIS中Python使用及批量裁剪示技巧讲解 !

arcgis中img 批量转换tif_在ArcGIS中Python使用及批量裁剪示技巧讲解 !

时间:2018-09-21 02:12:53

相关推荐

arcgis中img 批量转换tif_在ArcGIS中Python使用及批量裁剪示技巧讲解 !

ArcGIS中的工具均提供Python函数,方便支持批量处理。

以掩膜裁剪(提取分析/Extract by Mask)为例,

Python资源共享群:484031800

可以查找到帮助文档“按掩膜提取”(源1)(源2),路径“工具参考/工具/Spatial Analyst 工具箱/按掩膜提取”函数为:Extract by Mask

Extract by Mask的基本语法是:

ExtractByMask (in_raster, in_mask_data)

in_raster:提取像元的输入栅格。

in_mask_data:用于定义提取区域的输入掩膜数据。它可以是栅格,也可以是要素数据集。

代码示例

以下以批量读取裁剪某文件夹下的tif数据为例(特别注意Python2脚本循环语句格式的空格不能用Tab,否则会报错Indent;

另外在使用不同的矢量裁剪同一影像时,为保证裁剪后范围一致需设置范围为输入栅格范围。例如下面的:

rd = arcpy.sa.Raster(inRaster)

# Set the extent environment as the raster, very important for clip with different vector

arcpy.env.extent = rd.extent):

# Import system modules

import arcpy

from arcpy import env

from arcpy.sa import *

# Set environment settings

env.workspace = "D:/img"

rasterList = arcpy.ListRasters("*","tif")

#输出路径

output_path = "D:/imgMask/"

# mask shp

inMaskData = "D:/range.shp"

for raster in rasterList:

print raster

# Set local variables

inRaster = raster

rd = arcpy.sa.Raster(inRaster)

# Set the extent environment as the raster, very important for clip with different vector

arcpy.env.extent = rd.extent

# Execute ExtractByMask

outExtractByMask = ExtractByMask(inRaster, inMaskData)

# Save the output

out = output_path + inRaster #对生成文件进行命名

outExtractByMask1.save(out)

代码执行

方式一:将代码保存为单独的py文件,cmd或其它IDE执行。cmd执行命令(如何独立运行脚本):

C:Python27ArcGIS10.3python.exe my_script.py

方式二:ArcGIS安装的Python IDE里执行

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。