Created
March 4, 2021 15:29
-
-
Save nmathewa/849aa312253415dae44353b823435d89 to your computer and use it in GitHub Desktop.
gdal_resample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Created on Thu Mar 4 19:14:00 2021 | |
@author: nma | |
""" | |
from osgeo import gdal | |
## file to be converted | |
in_file = "in_file.tif" | |
inn = gdal.Open(in_file,gdalconst.GA_ReadOnly) | |
innproj = inn.GetProjection() | |
innTrans = inn.GetGeoTransform() | |
# Reference file | |
reffile = "reference.tif" | |
refe = gdal.Open(reffile,gdalconst.GA_ReadOnly) | |
refeproj = refe.GetProjection() | |
refeTrans = refe.GetGeoTransform() | |
refeband = refe.GetRasterBand(1) | |
x = refe.RasterXSize | |
y = refe.RasterYSize | |
outfile = "oufile.tif" | |
dst = gdal.GetDriverByName('GTiff').Create(outfile, x, y, 1, gdalconst.GDT_Float32) | |
output = driver.Create(outfile,x,y,1,refeband.DataType) | |
output.SetGeoTransform(refeTrans) | |
output.SetProjection(refeproj) | |
gdal.ReprojectImage(inn,dst,innproj,refeproj,gdalconst.GRA_Bilinear) | |
ds = gdal.Translate(outfile,in_file, xRes=0.01 | |
,yRes=0.01,resampleAlg="bilinear", format='GTiff') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment