首页 > 代码库 > ArcGIS Python实现批量化裁剪影像

ArcGIS Python实现批量化裁剪影像

一、程序代码:

import arcpy
arcpy.CheckOutExtension("spatial")
arcpy.gp.overwriteOutput=1
arcpy.env.workspace = "F:\\Modis_16\\1Moasic"
rasters = arcpy.ListRasters("*", "tif")
mask= "F:\\Vegetation Change\\Data\\Bound\\bound_Buffer_Polygon.shp"
for raster in rasters:
    print(raster)
    out= "F:\\Vegetation Change\\Data\\GIMMS Data\\new\\"+"ma_"+raster[0:8]
    arcpy.gp.ExtractByMask_sa(raster, mask, out)
    print("ma_"+raster[0:8]+"  has done")
print("All done")

二、注意事项:

    1.arcpy.gp.overwriteOutput=1即覆盖之前的文件;

    2.输入的是.tif文件,输出的是Grid文件;

    3.raster[0:8]表示从第0个开始取8个字符串;

    4.bound_Buffer_Plygon.shp后缀名不可或缺。

三、运行情况:


ArcGIS Python实现批量化裁剪影像