I have 5 numpy arrays of the form nx, ny
lons.shape = (nx,ny)
lats.shape = (nx,ny)
reds.shape = (nx,ny)
greens.shape = (nx,ny)
blues.shape = (nx,ny)
The modes of red, green and blue colors contain values from 0 to 255, and lat / lon arrays contain pixel coordinates in latitude / longitude.
My question is how to write this data into a geotype?
Ultimately, I want to build an image using a basemap.
Here is the code that I have so far, however I get a huge GeoTIFF file (~ 500 MB) and it looks empty (just a black image). Also note that nx, ny = 8120, 5416.
from osgeo import gdal
from osgeo import osr
import numpy as np
import h5py
import os
os.environ['GDAL_DATA'] = "/Users/andyprata/Library/Enthought/Canopy_64bit/User/share/gdal"
input_path = '/Users/andyprata/Desktop/modisRGB/'
with h5py.File(input_path+'red.h5', "r") as f:
red = f['red'].value
lon = f['lons'].value
lat = f['lats'].value
with h5py.File(input_path+'green.h5', "r") as f:
green = f['green'].value
with h5py.File(input_path+'blue.h5', "r") as f:
blue = f['blue'].value
r = red.astype('uint8')
g = green.astype('uint8')
b = blue.astype('uint8')
nx = red.shape[0]
ny = red.shape[1]
xmin, ymin, xmax, ymax = [lon.min(), lat.min(), lon.max(), lat.max()]
xres = (xmax - xmin) / float(nx)
yres = (ymax - ymin) / float(ny)
geotransform = (xmin, xres, 0, ymax, 0, -yres)
dst_ds = gdal.GetDriverByName('GTiff').Create('myGeoTIFF.tif', ny, nx, 3, gdal.GDT_Float32)
dst_ds.SetGeoTransform(geotransform)
srs = osr.SpatialReference()
srs.ImportFromEPSG(3857)
dst_ds.SetProjection(srs.ExportToWkt())
dst_ds.GetRasterBand(1).WriteArray(r)
dst_ds.GetRasterBand(2).WriteArray(g)
dst_ds.GetRasterBand(3).WriteArray(b)
dst_ds.FlushCache()
dst_ds = None