gdal reproject and resample python

Solutions on MaxInterview for gdal reproject and resample python by the best coders in the world

showing results for - "gdal reproject and resample python"
Carl
17 Mar 2020
1from osgeo import gdal, gdalconst
2
3src_filename='src.tif'
4match_filename='to_match.tif'
5dst_filename='dst.tif'
6
7#source
8src = gdal.Open(src_filename, gdalconst.GA_ReadOnly)
9src_proj = src.GetProjection()
10src_geotrans = src.GetGeoTransform()
11
12#raster to match
13match_ds = gdal.Open(match_filename, gdalconst.GA_ReadOnly)
14match_proj = match_ds.GetProjection()
15match_geotrans = match_ds.GetGeoTransform()
16wide = match_ds.RasterXSize
17high = match_ds.RasterYSize
18
19#output/destination
20dst = gdal.GetDriverByName('Gtiff').Create(dst_filename, wide, high, 1, gdalconst.GDT_Float32)
21dst.SetGeoTransform(match_geotrans)
22dst.SetProjection(match_proj)
23
24#run
25gdal.ReprojectImage(src, dst, src_proj, match_proj, gdalconst.GRA_NearestNeighbour)
26
27del dst # Flush