私はPythonでGDALを使用して.tifファイルを作成しようとしています。ファイルを作成していますが、参照するたびに「プレビューなし」と表示されます。今、私は入力ファイルのコピーを作るようにしようとしています。 ======GDALラスター出力
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
============================更新:ここに私のコードです=================================== は ...いくつかの発見をした私は、変換の方法を研究してきました統計的な正規化を使用して、ある数値形式から別の数値形式に変換します。私は、入力データを処理し、次のアルゴリズムを使用してに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
私はコピーしたかった主な理由は、計算に基づいて更新されたデータを書き出す、その後、私は読むことができたことを証明することでした。
単色の色ではなく、カラーランプを使用して出力データを書き出す方法はありますか?
問題を見つけました。私が作成した出力ファイルのタイプに適切なビューアがありませんでした。 Int16は、Microsoftの製品ではサポートされていません。私はBrava Readerをダウンロードしてインストールしました。生成できる出力のほとんどを見ることができます。 – Pat