赞
踩
(2条消息) Python多种方式实现批量裁剪_xinxgcq的博客-CSDN博客_python clip by mask layer,(2条消息) Python批量裁剪MODIS栅格影像数据——利用shp文件裁剪tif影像_python shp裁剪tif_傲寒。的博客-CSDN博客
- # -*- coding: utf-8 -*-
- """
- 根据一个矢量文件对多个栅格数据进行批量掩膜裁剪
- YMJ, 20230119, 14:45
- """
-
- import arcpy
- from arcpy import env
- from arcpy.sa import *
-
- #工作环境,待处理文件所在位置,输出位置
- env.workspace = "D:\RUANJIAN\Python\YMJdata\Practice\_tiff"
- outputpath = "D:\RUANJIAN\Python\YMJdata\Practice\_tiff\clip"
-
- #读取tiff文件
- rasters = arcpy.ListRasters("*", "tif")
- #掩膜数据
- inMaskData = "D:\RUANJIAN\Python\YMJdata\Practice\oundary\country_polygon.shp"
-
- #遍历图层,进行掩膜裁剪
- for raster in rasters:
- file_name = raster.split(".")[0]
- print(file_name)
- arcpy.CheckOutExtension("Spatial")
- outExtractByMask = ExtractByMask(raster, inMaskData)
- outExtractByMask.save(outputpath + "/" + file_name + "_clip.tif")
-
- print("finished")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。