numpy 配列出力を GeoTiff として保存しようとしており、コードはほとんど正常に実行されていますが、出力画像にはデータのセピア調のスケールがあります (私のコードが画像に対して生成するような通常の配色ではなく)、および黒の背景 (私のコードが画像用に生成する白/データなしの背景の代わりに)。
これは、配列を GeoTiff に保存するためのコードです。no-data = 0 にして、データ スキームを色付けすることについて、どこかに行を追加できますか?
from osgeo import gdal, osr, ogr, os
from gdalconst import *
def array2raster(newRasterfn,rasterOrigin,pixelWidth,pixelHeight,array):
cols = array.shape[1]
rows = array.shape[0]
originX = rasterOrigin[0]
originY = rasterOrigin[1]
driver = gdal.GetDriverByName( 'GTiff' )
outRaster = driver.Create(newRasterfn, cols, rows, 1, gdal.GDT_Float32)
outRaster.SetGeoTransform((originX, pixelWidth, 0, originY, 0, pixelHeight))
outband = outRaster.GetRasterBand(1)
outband.WriteArray(array)
# outRaster = driver.Create( 'CORDC_GTIFF/working_CA.tiff', 300, 300, 1, gdal.GDT_Int32)
proj = osr.SpatialReference()
proj.ImportFromEPSG(4326)
outRaster.SetProjection(proj.ExportToWkt())
# geotransform = (1,0.1,0,40,0,0.1)
rasterOrigin = (-127,42)
pixelWidth = .01
pixelHeight = .01
newRasterfn = 'CORDC_GTIFF/cordc_working_CA.tif'
array = np.array(spd)
reversed_arr = array[::-1] # reverse array so the tif looks like the array
array2raster(newRasterfn,rasterOrigin,pixelWidth,pixelHeight,reversed_arr) # convert array to raster