# 第1节 批量裁剪和批量重采样

* 说明：本人这是刚入门时学的 python和arcgis,由于快要毕业啦，不管好不好用，反正当初是实现了我要的功能，虽然现在回头看下确实比较烂，但是作为一种经验，也就放出来啦，毕业就转行了，这里就当做是一个留念吧。

## 1.利用arcgis的 ExtractByMask 工具进行批量的裁剪

```python
import arcpy
from arcpy.sa import *
path = "G:/GEE/spartinaWater"  # 工作路径
arcpy.env.workspace = path
rasters = arcpy.ListRasters("*0.tif", "tif")
arcpy.CheckOutExtension("Spatial")
inMaskDataAll = ["site4_20171231_20180931.tif"]
for inMaskData in inMaskDataAll: 由于我需要裁剪的不仅是 2 个掩模，所以用了两个 for 循环
    for inRaster in rasters:
        ractByMask = ExtractByMask(inRaster, inMaskData) # 裁剪的工具
        ractByMask.save(path+'/'+str(inMaskData)[:5]+'_'+inRaster[:25]+'.tif')
        print(inRaster)
```

## 2.下面是利用 Resample\_management 批量进行重采样的工具

```python
rasters = arcpy.ListRasters("site*", "tif")
for inRaster in rasters:
    arcpy.Resample_management(inRaster, path+'/'+inRaster[:-4]+'_re.tif', 
                              "20171002R2.tif", "CUBIC")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://comingboy.gitbook.io/gee/di-6-zhang/6.1-jie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
