It seems an easy question, but I can't find the Python equivalent of R's Dissaggregate:
Disaggregate a RasterLayer to create a new RasterLayer with a higher resolution (smaller cells)
I expected it in GDAL but no luck so far.
It seems an easy question, but I can't find the Python equivalent of R's Dissaggregate:
Disaggregate a RasterLayer to create a new RasterLayer with a higher resolution (smaller cells)
I expected it in GDAL but no luck so far.
Sounds like you might want something like numpy.repeat
. Open the raster as a numpy array by doing array = gdal.Open(file).ReadAsArray()
, then use np.repeat
for both the x and y axes. Here is an example:
import numpy as np
>>> array = np.random.randint(10,size =(3,3))
>>> array
array([[6, 1, 6],
[9, 7, 0],
[3, 1, 7]])
>>> downsampled_in_x = np.repeat(array,2,axis = 1)
>>> downsampled_in_x
array([[6, 6, 1, 1, 6, 6],
[9, 9, 7, 7, 0, 0],
[3, 3, 1, 1, 7, 7]])
>>> downsampled_in_both = np.repeat(downsampled_in_x,2,axis = 0)
>>> downsampled_in_both
array([[6, 6, 1, 1, 6, 6],
[6, 6, 1, 1, 6, 6],
[9, 9, 7, 7, 0, 0],
[9, 9, 7, 7, 0, 0],
[3, 3, 1, 1, 7, 7],
[3, 3, 1, 1, 7, 7]])
See numpy / scipy docs for more info
Note that this is different from resampling, which one could accomplish by using gdal_translate
or similar.