Python多种方式实现批量裁剪
程序员文章站
2024-02-13 17:44:16
...
Python多种方式实现批量裁剪
栅格裁剪(ExtractByMask):同一矢量文件,不同栅格文件
#栅格裁剪(ExtractByMask):同一矢量文件,不同栅格文件
#Author: Changqing Guo
# coding: utf-8
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.env.workspace = "Z:/0/01/01"
arcpy.env.overwriterOutput = True
outfiles = "Z:/0/01/05caijian/02et"
clipfiles = "Z://New_Shapefile.shp"
infiles = arcpy.ListFiles("*.tif")
for filename in infiles:
print("Processing:" + filename)
inputfiles = arcpy.env.workspace + "/" + filename
outputfiles = outfiles + "/" + filename
outExtractByMask = ExtractByMask(inputfiles, clipfiles)
outExtractByMask.save(outputfiles + ".tif")
print "***OVER***"
print arcpy.GetMessages()
栅格裁剪(ExtractByMask):同一栅格文件,不同矢量文件
#栅格裁剪(ExtractByMask):同一栅格文件,不同矢量文件
#Author: Changqing Guo
# coding: utf-8
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.env.workspace = "D:/Test/shp"
arcpy.env.overwriterOutput = True
outfiles = "D:/Test/out"
infiles = "D:/Test/Tif/00_dem.tif"
clipfiles = arcpy.ListFiles("*.shp")
for filename in clipfiles:
print("Processing:" + filename)
clipputfiles = arcpy.env.workspace + "/" + filename
outputfiles = outfiles + "/" + filename[:-4]
outExtractByMask = ExtractByMask(infiles, clipputfiles)
outExtractByMask.save(outputfiles + ".tif")
print "***OVER***"
print arcpy.GetMessages()
矢量裁剪(Clip_analysis)
#矢量裁剪(Clip_analysis)
#Author: Changqing Guo
# coding: utf-8
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.env.workspace = "C:/Downloads"
arcpy.env.overwriterOutput = True
outfiles = "E:/01data/ruoergai"
infiles = "C:/Downloads/ld_dian/ld_dian.shp"
clipfiles = arcpy.ListFiles("*.shp")
for filename in clipfiles:
print("Processing:" + filename)
inclipfiles = arcpy.env.workspace + "/" + filename
outputfiles = outfiles + "/" + filename
arcpy.Clip_analysis(infiles,inclipfiles,outputfiles + ".shp","")
print "***OVER***"
print arcpy.GetMessages()