import argparse
from osgeo import gdal
def convert_ascii_to_tiff(in_asc_path: str, out_tiff_path: str, band_count: int):
try:
print("Processing...")
src_ds = gdal.Open(in_asc_path)
data = src_ds.ReadAsArray()
driver = gdal.GetDriverByName('GTiff')
width = src_ds.RasterXSize
height = src_ds.RasterYSize
dst_ds = driver.Create(out_tiff_path, width, height, bands=band_count, eType=gdal.GDT_Float32)
for i in range(band_count):
dst_ds.GetRasterBand(i+1).WriteArray(data)
dst_ds.SetGeoTransform(src_ds.GetGeoTransform())
dst_ds.SetProjection(src_ds.GetProjection())
src_ds = None
dst_ds = None
print("Conversion completed successfully.")
except Exception as e:
print(f"An error occurred during conversion:{str(e)}")
convert_ascii_to_tiff("183.ASC","183.tif",band_count=1)