【ArcPy】使用面要素类分割影像

Python工具代码,非Python窗口脚本,可以自行编辑处理一下。

# coding=gbk
import arcpy
from arcpy import da as da
    
def getFieldUniqueValue(inTable,inField):
        rows=arcpy.da.SearchCursor(inTable,inField)
        value_lst=[row[0] for row in rows]
        return set(value_lst)


def main():
    lyr=arcpy.GetParameter(0)
    fld=arcpy.GetParameterAsText(1)
    isUseShape=arcpy.GetParameterAsText(2)
    rst=arcpy.GetParameter(3)
    out_folder=arcpy.GetParameterAsText(4)
    clipping_geometry='ClippingGeometry' if isUseShape else 'NONE'
    uniqueValues=getFieldUniqueValue(lyr,fld)
    recordCount=len(uniqueValues)
    # arcpy.AddMessage(recordCount)
    arcpy.SetProgressor("step","存在 {} 个影像待输出。".format(recordCount),0,recordCount,1)
    for val in uniqueValues:
        arcpy.SetProgressorLabel("{} 正在输出……".format(val))
        arcpy.SetProgressorPosition()
        arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",u"{0}='{1}'".format(fld,val)) 
        arcpy.Clip_management(rst,'#',u'{}\{}.tif'.format(out_folder,val),lyr,0,clipping_geometry)
    arcpy.SelectLayerByAttribute_management(lyr,'CLEAR_SELECTION')


if __name__ == '__main__':
    main()

 

posted @ 2023-02-12 11:21  yzhyingcool  阅读(71)  评论(0编辑  收藏  举报