再议使用Python批量裁切栅格
2015-07-21 15:30
645 查看
曾经写过《使用Python脚本批量裁切栅格》,但今天又遇到这个情况则发现了问题。我们遇到的实际问题往往是有一个需要裁剪的影像(大块的),另外有一个矢量面,现在需要按矢量面每一个要素进行裁剪,无奈arcgis里的工具无法方便地做到。只能自己写工具,这次使用了clip而不是ExtractByMask,因为ExtractByMask有很多限制!
下面是工具的操作示例:按每一个要素进行裁剪栅格,输出栅格以选择的字段命名,前提是字段的每个值是唯一的。
其中,输出类型这个combox设置方法是:
下面是消息输入和裁剪矢量表的属性表:
下面是Python源代码
下面是工具的操作示例:按每一个要素进行裁剪栅格,输出栅格以选择的字段命名,前提是字段的每个值是唯一的。
其中,输出类型这个combox设置方法是:
下面是消息输入和裁剪矢量表的属性表:
下面是Python源代码
# --------------------------------------------------------------------------- # Purpose : ClipRasterByFeature # Author :gisweis # Date :2015.7.21 # Version : ArcGIS 10.1 # Email :liweis2014@hotmail.com # Notes : # --------------------------------------------------------------------------- import sys reload(sys) sys.setdefaultencoding( "utf-8" ) import arcpy import string try: raster = arcpy.GetParameterAsText(0) #clip raster clip_feat = arcpy.GetParameterAsText(1) #clip featureclass field = arcpy.GetParameterAsText(2) #name field outworkspace = arcpy.GetParameterAsText(3) #output ws outtype = arcpy.GetParameterAsText(4) #output ws total = int(arcpy.GetCount_management(clip_feat).getOutput(0)) count= 1 for row in arcpy.SearchCursor(clip_feat): mask=row.getValue("Shape") extent=str(mask.extent.XMin)+" " +str(mask.extent.YMin)+" " +str(mask.extent.XMax)+" " +str(mask.extent.YMax) outPath=outworkspace+"\\"+str(row.getValue(field)+outtype) arcpy.AddMessage("chipping: " + str(row.getValue(field)) + "...count:"+str(total)+"\\"+str(count)) arcpy.Clip_management(raster,extent,outPath,mask,"0","ClippingGeometry") count=count+1 except arcpy.ExecuteError: print arcpy.GetMessages()
相关文章推荐
- 安装配置Python+Numpy+Scipy+Matplotlib环境
- python 安装 库
- python下导入自己定义的模块的方法
- [python] 发POST请求
- Python编辑器设置(包括Visual Studio Code和Sublime Text3)
- Python自省(反射)指南
- windows 下python安转numpy、opencv包
- Python开发者最常犯的10个错误
- Python之列表推导式List comprehensions例解
- 飘逸的python - inspect谁调用了我
- python实现查找文件名包含指定字符串的文件
- [python] 发GET请求
- python 中 高阶函数
- python sqlite3 插入数据例程
- python 使用list和tuple
- 使用python客户端访问impala
- python enumerate 用法
- Python的惯例
- Python资源
- [python-1]数据类型、控制流语句、模块、函数和类