Skip to content

Instantly share code, notes, and snippets.

@zerebubuth
Created February 16, 2016 19:57
Show Gist options
  • Save zerebubuth/96d7d9ca8967e9f22cca to your computer and use it in GitHub Desktop.
Save zerebubuth/96d7d9ca8967e9f22cca to your computer and use it in GitHub Desktop.
Simple GDAL/numpy that doesn't seem to work
from osgeo import gdal
import numpy as np
import sys
xsize = 266
ysize = 276
drv = gdal.GetDriverByName("MEM")
ds = drv.Create('', xsize, ysize, 1, gdal.GDT_Float32)
band = ds.GetRasterBand(1)
arr = band.ReadAsArray(0, 0, xsize, ysize)
if (xsize, ysize) != arr.shape:
print>>sys.stderr, "%r != %r" % ((xsize, ysize), arr.shape)
raise Exception, "Array shape should match what we requested."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment