0

What I want to do is take an image of N bands, merge it with another one of 1 band but preserve the geographic information of the initial image in the merged image.

I can already do the merge but the geo reference information comes out incomplete.

Here is my code:

def array2raster(new_file_name,array,data):
bandas = array.shape[2]
cols = data.RasterXSize
rows = data.RasterYSize
origen = data.GetGeoTransform()
origenX = origen[0]
origenY = origen[3]
pixelWidth=origen[1]
pixelHeight=origen[5]
driver = gdal.GetDriverByName("GTiff")
sr = osr.SpatialReference()
data.SetProjection(sr.ExportToWkt())



outRaster = driver.Create(new_file_name, cols, rows, bandas, gdal.GDT_Byte)
outRaster.SetGeoTransform((origenX, pixelWidth, origen[2], origenY,origen[4], pixelHeight))

for i in range(bandas):
    band = i+1
    banda = array[:,:,i]

    outRaster.GetRasterBand(band).WriteArray(banda)
    outRaster.GetRasterBand(band).SetNoDataValue(np.nan)
    i = i+1


#s_ref =gdal.Copy
s_ref = osr.SpatialReference()
s_ref.ImportFromEPSG(4326)
outRaster.SetProjection(s_ref.ExportToWkt())
print("se guarda la info con éxito")
outRaster.FlushCache()

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
  • 2
    Welcome to GIS SE. Although we appreciate all cultures and languages, this is an English language site. Please edit your question to include the English translation. – Aaron Oct 12 '21 at 22:27
  • You're creating a spatial reference object but not assigning it, have a look at https://gis.stackexchange.com/questions/60371/getting-coordinate-system-name-from-spatialreference-using-gdal-python – Michael Stimson Oct 13 '21 at 01:04

0 Answers0