GDAL光栅输出

Pat*_*Pat 7 python io raster arcgis gdal

我正在尝试在python中使用GDAL创建一个.tif文件.它正在创建一个文件,但每当我浏览它时都会说"无法预览".现在,我只是想让它来制作输入文件的副本.这是我的代码:

gdal.AllRegister()

inDs = gdal.Open("C:\\Documents and Settings\\patrick\\Desktop\\tiff elevation\\EBK1KM\\color_a2.tif")
if inDs is None:
  print 'Could not open image file'
  sys.exit(1)
else:
    print "successfully opened input file"

rows = inDs.RasterYSize
cols = inDs.RasterXSize
myband = inDs.GetRasterBand(1)
elev_data = myband.ReadAsArray(0,0,cols,rows)
driver = inDs.GetDriver()
outDs = driver.Create('C:\\Documents and Settings\\patrick\\Desktop\\tiff elevation\\EBK1KM\\new.tif', cols, rows, 1, GDT_Int32)

if outDs is None:
    print "couldn't open output file"
    sys.exit(1)

outBand = outDs.GetRasterBand(1)
outData = numpy.zeros((rows,cols),numpy.int16)
outBand.WriteArray(elev_data)
outBand.FlushCache()
outBand.SetNoDataValue(-99)
outDs.SetGeoTransform(inDs.GetGeoTransform())
outDs.SetProjection(inDs.GetProjection())
del outData
Run Code Online (Sandbox Code Playgroud)

============================更新===================== ====================做了一些发现......我研究了使用统计规范化从一种数字格式转换为另一种数字格式的方法.我处理输入数据并使用以下算法将其转换为uint8:

std = elev_data.std() #standard dev
avg = elev_data.mean()
arr = numpy.zeros((rows,cols),numpy.uint8)
for _i_ in _range_(_rows_):
    for _j_ in _range_(_cols_):
        arr[i,j] = (((out_elev[i,j]-avg)/std)*127)+128 #normalization formula
        #this puts all vals in range 1 to 255 (uint8)
dr = gdal.GetDriverByName("GTiff")
outDs = dr.Create("name",cols,rows,3,GDT_Byte) 
#creates and RGB file, accepts uint8 for input
outDs.GetRasterBand(1).WriteArray(arr) #write the output as shades of red
#this writes out a format viewable by microsoft products
Run Code Online (Sandbox Code Playgroud)

我想要复制的主要原因是为了证明我可以读入,然后根据计算写出更新的数据.

什么可能是一种方法,我可以使用颜色渐变写出输出数据,而不是只有一种颜色的阴影?

Dan*_*den 2

您的意思是当您尝试将 TIFF 文件预览为图像时,Windows 图片和传真查看器应用程序显示“无预览可用”?(参见下面的屏幕截图。)

没有可用的预览屏幕截图

请记住,TIFF 有许多不同的风格,而且并非所有风格都相同。特别是,Windows 图片和传真查看器不支持所有类型的 TIFF。

有一篇 Microsoft 知识库文章您无法使用 Windows 图片和传真查看器查看 TIFF 图像,其中部分内容如下:

Windows XP 中的 Windows 图片和传真查看器使用 Windows 图形设备接口 (GDI+)。GDI+ 支持许多传真标准压缩算法。然而,它可能与一些不经常使用的编码方案不兼容。

如果您正在寻找用于查看栅格数据(包括 GeoTIFF 栅格)的工具,我建议您免费使用OpenEV,您可以将其作为FWTools包的一部分获得。