更新港口文件

master
chenzenghui 2025-10-10 20:30:37 +08:00
parent acf441db4a
commit 5794cfbe49
1 changed files with 34 additions and 1 deletions

View File

@ -70,6 +70,38 @@ def write_envi(im_data, im_geotrans, im_proj, output_path):
dataset = None # 关闭文件
def write_allExtend(im_data, im_geotrans, im_proj, output_path):
"""
将数组数据写入ENVI格式文件
:param im_data: 输入的numpy数组2D或3D
:param im_geotrans: 仿射变换参数6元组
:param im_proj: 投影信息WKT字符串
:param output_path: 输出文件路径无需扩展名会自动生成.dat和.hdr
"""
im_bands = 1
im_height, im_width = im_data.shape
create_options=[
"COMPRESS=DEFLATE",
"PREDICTOR=2",
"ZLEVEL=6",
"TILED=YES",
]
# 创建ENVI格式驱动
driver = gdal.GetDriverByName("GTiff")
dataset = driver.Create(output_path, im_width, im_height, 1, gdal.GDT_Byte,options=create_options)
if dataset is not None:
dataset.SetGeoTransform(im_geotrans) # 设置地理变换参数
dataset.SetProjection(im_proj) # 设置投影
dataset.GetRasterBand(1).WriteArray(im_data)
dataset.FlushCache() # 确保数据写入磁盘
dataset = None # 关闭文件
def write_tiff(im_data, im_geotrans, im_proj, output_path):
"""
将数组数据写入ENVI格式文件
@ -476,7 +508,8 @@ def stretchSliceProcess(infilepath, outfolder,portfilestr, strechmethod):
im_data = im_data.astype(np.uint8)
rootname=Path(infilepath).stem
allImagePath=os.path.join(allpngfolder, rootname+"_all.png")
Image.fromarray(im_data).save(allImagePath,compress_level=0)
Image.fromarray(im_data).save(allImagePath,compress_level=9)
# write_allExtend(im_data, im_Geotrans, im_proj, allImagePath)
slice_ID=0
slice_ID=sliceShipDataset(rootname,im_data, src_im_data,im_Geotrans, im_proj, outfolder) # 舰船切片
slice_ID=slice_ID+1