# 当一个栅格文件覆盖多个区域,需要裁剪时会用到,比如这种情况:一个省的分类结果图,需要每个县单独出图
数据准备:单个栅格文件以及若干shp文件
语法
ExtractByMask (in_raster, in_mask_data)
代码
# -*- coding: utf-8 -*-
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
# shp所在的文件夹
env.workspace = "E:/bound"
# 裁剪后文件输出的文件夹
output_path="E:/clip"
# Set local variables
shps = arcpy.ListFeatureClasses()
# 需要裁剪的栅格
InValueRaster = "E:/1.GB/0.Wangjj/task1/landcover_mosaic.tif"
#这个可以忽略,为了看下当前有多少数据需要处理
count=0
for shp in shps:
count=count+1
print(count)
num=0
#循环
for shp in shps:
#获取文件名并去掉后缀
num=num+1
file_name = shp.split('.')[0]
print(file_name)
# Check out the ArcGIS S