I am using python 2.7.10. I am trying to read a big Raster with gdal and numpy array. But it show In MemoreErrors when i use this: band. ReadAsArray()
Note: this error occurs when input raster is very big not for all of the rasters
Here is my Code:
import sys, os, gdal, struct
from osgeo import osr
from gdalconst import *
import numpy
import time
import subprocess
startTime=time.time()
gdal.UseExceptions()
##OutCellSize = 1000
##OutFormat = "GTiff"
# Command line arguments
# change to known values if you prefer
InRas= r"F:\Geodaten\Eigene\Luftbild\Orthobilder\20120502\Aschhorn_mosaik.jpg"
src_ds=gdal.Open(InRas)
if src_ds is None:
print 'Unable to open %s' % InRas
sys.exit(1)
print "gdal can open the file"
srcband = src_ds.GetRasterBand(1)
try:
bandArray = srcband.ReadAsArray()
print bandArray
except:
print "cannot convert raster to array.\n" "Need to compress raster"
# obtaining reference info from input raster
geotransform = src_ds.GetGeoTransform()
originX = geotransform[0]
originX = geotransform[0]
originY = geotransform[3]
pixelWidth = geotransform[1]
pixelHeight = geotransform[5]
cols = src_ds.RasterXSize
rows = src_ds.RasterYSize ###we are here
raster_srs = osr.SpatialReference()
raster_srs.ImportFromWkt(src_ds.GetProjectionRef())
# creating raster in mepory as outraster from input
try:
dst_ds = gdal.GetDriverByName("MEM").Create('', src_ds.RasterXSize, src_ds.RasterYSize, 1, gdal.GDT_Byte)
dst_ds.SetGeoTransform(geotransform)
# Create for target raster the same projection as for the value raster
dst_ds.SetProjection(raster_srs.ExportToWkt())
except:
print "Unable to create in memory raster"
How could I solve this issue. Other wise I am not able to do further analysis.
geotransform = src_ds.GetGeoTransform()