Skip to content

Instantly share code, notes, and snippets.

@nmathewa
Created March 4, 2021 14:19
Show Gist options
  • Save nmathewa/ce2f30761b73217dfc65541a2040bcdb to your computer and use it in GitHub Desktop.
Save nmathewa/ce2f30761b73217dfc65541a2040bcdb to your computer and use it in GitHub Desktop.
new_GTiff
"""
Created on Thu Mar 4 19:14:00 2021
@author: nma
"""
import numpy as np
from osgeo import gdal,gdal_array
lat_val = np.arange(10,15,0.1)
lon_val = np.arange(70,85,0.1)
lat,lon = len(lat_val),len(lon_val)
array = np.random.random((lat,lon))
driver_ = gdal.GetDriverByName("GTiff")
out_dir = "/home/nma/Downloads/out.tif"
tif = driver_.Create(out_dir, lon, lat, 6, gdal.GDT_Float32)
tif.SetGeoTransform((lon_val[0],0.1,0.0,lat_val[-1],0.0,0.1))
tif.GetRasterBand(1).WriteArray(array)
tif.FlushCache() ##saves to disk!!
tif = None
band=None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment