Is it possible to write data line by line using gdal's WriteArray, rather than creating and feeding it an entire array?
I've run into a MemoryError
when creating an numpy array of size (50539,98357). I suppose I could get around this by using PyTables, but I'd rather not complicate things
>>> import numpy
>>> cols = 50539
>>> rows = 98357
>>> a1 = np.zeros((cols,rows))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'np' is not defined
>>> import numpy as np
>>> a1 = np.zeros((cols,rows))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError
Update: I ended up using Abudis's solution combined with a sparse matrix in which I saved the points, pulling out each row as a "dense" or standard matrix. Comments welcome.
dataset = driver.Create(filename, cols, rows, number_of_bands, band_type)
band = dataset.GetRasterBand(1)
offset = 1 # i.e. the number of rows to write with each iteration
# values, pixel_x, and pixel_y defined earlier in my script
data = scipy.sparse.csr_matrix((values,(pixel_y,pixel_x)),dtype=float)
# iterate data writing for each row in data sparse array
for i in range(data.shape[0]):
data_row = data[i,:].todense() # output row of sparse array as standard array
band.WriteArray(data_row,0,offset*i)
band.SetNoDataValue(NULL_VALUE)
band.FlushCache()