数据准备
遥感影像和面矢量
相关代码
import arcpy
import os
def mkdir(path):
if not os.path.exists(path):
os.mkdir(path)
block_shp = 'fenqu/sandt_fenqu.shp'
img_path = 'abaga_old.TIF'
save_path = 'masks'
mkdir(save_path)
cursor = arcpy.UpdateCursor(block_shp)
count = 0
for row in cursor:
value = row.getValue('FID')
temp = 'tmp_shp_block/'
mkdir(temp)
out_block = os.path.join(temp, str(count) + '.shp')
if not os.path.exists(out_block):
arcpy.MakeFeatureLayer_management(block_shp, str(count))
arcpy.SelectLayerByAttribute_management(str(count), 'NEW_SELECTION', '"FID" = ' + str(value))
arcpy.CopyFeatures_management(str(count), out_block)
out_block_tif = os.path.join(save_path, str(count) + '.tif')
arcpy.Clip_management(in_raster=img_path, out_raster=out_block_tif, in_template_dataset=out_block,
nodata_value="0", clipping_geometry="NONE", maintain_clipping_extent="NO_MAINTAIN_EXTENT")
count += 1
部分结果展示