Commit ec57b91b authored by Hoek, Steven's avatar Hoek, Steven
Browse files

A library to copy a raster into memory. This is esp. useful for raster types...

A library to copy a raster into memory. This is esp. useful for raster types such as TileTiffRaster which seem not to support repeated reading
parent 5c95c1b2
......@@ -3,4 +3,5 @@ from .floatingpointraster import FloatingPointRaster;
from .gridenvelope2d import GridEnvelope2D;
from .netcdf4envelope2d import Netcdf4Envelope2D;
from .hdf5raster import Hdf5Raster;
from .netcdf4raster import Netcdf4Raster;
\ No newline at end of file
from .netcdf4raster import Netcdf4Raster;
from .rowtiffraster import RowTiffRaster
\ No newline at end of file
import lmgeo.formats.inmemoryraster as imr
from lmgeo.formats.raster import Raster
from lmgeo.formats.gridenvelope2d import GridEnvelope2D
import numpy as np
def copyToMemory(myraster):
# Check input
if not isinstance(myraster, Raster):
raise Exception("Input is not a raster")
if not isinstance(myraster, GridEnvelope2D):
raise Exception("Input is not a grid envelope")
result = None
# Get particulars from the input
numpy_type = myraster.get_numpy_type()
mydata = np.zeros((myraster.nrows, myraster.ncols), dtype=numpy_type)
if numpy_type in [, np.uint16, np.uint32, np.int16, np.int32]:
fmt = 'i'
fmt = 'f'
nrows = myraster.nrows
ncols = myraster.ncols
nodatavalue = myraster.nodatavalue
# Use them to initialise a InMemory raster
result = imr.InMemoryRaster("C:\dummy_folder\dummyfile.nix", mydata, fmt)
if not'w', ncols, nrows, myraster.xll, myraster.yll, myraster.dx, nodatavalue):
raise Exception("Unable to initialise InMemoryRaster.")
# Now copy the data
for i in range(myraster.nrows):
line =
line.shape = (ncols,)[i,:] = line
except Exception as e:
raise Exception("Error in module copylib: %s" + str(e))
return result
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment