1

I'm trying to plot GIS data, a tiff file using gdal and then imshow() function but I am getting the following error -

enter image description here

My code is -

import gdal
import sys
import matplotlib.pyplot as pyplot
import numpy as np
import matplotlib as ml


try:
    tif = gdal.Open('lulc250k_1415_13861.tif')
    tifArray = tif.ReadAsArray()
except:
    print 'The file does not exist.'
    sys.exit(0)

band1 = tif.GetRasterBand(1)

band1Array = band1.ReadAsArray()

pyplot.imshow(band1Array)
pyplot.show()

The gdalinfo of the file -

Driver: GTiff/GeoTIFF
Files: lulc250k_1415_13861.tif
Size is 32716, 22789
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (72.486328125000000,32.233886718750000)
Pixel Size = (0.000509086484824,-0.000509086072228)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  72.4863281,  32.2338867) ( 72d29'10.78"E, 32d14' 1.99"N)
Lower Left  (  72.4863281,  20.6323242) ( 72d29'10.78"E, 20d37'56.37"N)
Upper Right (  89.1416016,  32.2338867) ( 89d 8'29.77"E, 32d14' 1.99"N)
Lower Right (  89.1416016,  20.6323242) ( 89d 8'29.77"E, 20d37'56.37"N)
Center      (  80.8139648,  26.4331055) ( 80d48'50.27"E, 26d25'59.18"N)
Band 1 Block=32716x1 Type=Byte, ColorInterp=Palette
  NoData Value=0
  Color Table (RGB with 256 entries)
  • please add gdalinfo output on lulc250k_1415_13861.tif – Ian Turton Jun 12 '18 at 15:16
  • @IanTurton I've updated the question with gdalinfo! – Tush_08 Jun 12 '18 at 21:45
  • Do you need to plot this in Python? If not, just drag it into QGIS. If it's still slow to load, you can build overviews on it. – Jon Jun 12 '18 at 22:13
  • And the tool for building overviews is gdaladdo gdal.org/gdaladdo.html. – user30184 Jun 12 '18 at 23:15
  • @Jon I do need to plot this in python. – Tush_08 Jun 13 '18 at 9:56
2

A MemoryError like this usually means that something ran out of memory (i.e. it's too big for your system to process as is). Your image dimensions (number of pixels) and data type for each pixel (uint8, float32, etc.) will influence how much memory is used. This type of error can also be related to figures hanging around in memory.

See this tutorial for info on clearing out old figures from memory: https://realpython.com/python-matplotlib-guide/

Some similar questions also suggest using the PIL library as one solution:

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.