2

I use a function on python (3.5) to create GTIFF with GDAL:

def array2raster2(fname,   matriz, geot, proj):
    drv = gdal.GetDriverByName("GTiff")
    dst_ds = drv.Create(fname, matriz.shape[1], matriz.shape[0], 3,  gdal.GDT_UInt16)
    dst_ds.SetGeoTransform(geot)
    dst_ds.SetProjection(proj)
    dst_ds.GetRasterBand(1).WriteArray(matriz[:, :, 0])  # write r-band to the    raster
    dst_ds.GetRasterBand(2).WriteArray(matriz[:, :, 1])  # write g-band to the raster
    dst_ds.GetRasterBand(3).WriteArray(matriz[:, :, 2])# write g-band to the raster
    dst_ds.FlushCache()
    dst_ds=None

and works fine, but when I open again the image with gdal.Open() and gdal.ReadAsArray() and check the shape, instead of i.e. (100, 101, 3), it shows (3, 100, 101), can anyone tell me why?

Also when I open the GTIFF on ENVI the orders of band is BGR, when I am saving the image on RGB.

2

Try to set colour interpretation of your bands:

dst_ds.GetRasterBand(1).SetRasterColorInterpretation(gdal.GCI_RedBand)
dst_ds.GetRasterBand(2).SetRasterColorInterpretation(gdal.GCI_GreenBand)
dst_ds.GetRasterBand(3).SetRasterColorInterpretation(gdal.GCI_BlueBand)

Also you can try to reverse the order of channels while filling pixels values.

dst_ds.GetRasterBand(3).WriteArray(matriz[:, :, 0])  # write r-band to the    raster
dst_ds.GetRasterBand(2).WriteArray(matriz[:, :, 1])  # write g-band to the raster
dst_ds.GetRasterBand(1).WriteArray(matriz[:, :, 2])# write g-band to the raster
  • Thanks a lot, the first option was the one I needed, problem solved – Ivan Nov 9 '17 at 16:21
  • actually there has been another issue, when add a 4th band, NIR in this case, when opening on ENVI again the 4th band is show as RED, how can I fix that? – Ivan Nov 30 '17 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.