[gdal-dev] AttributeError: 'MaskedArray' object has no attribute
'typecode' -- when writing GeoTiff
Greg Fiske
gfiske at whrc.org
Fri Jul 17 15:45:49 EDT 2009
Dear list,
In python, I'm writing GeoTiff files from numpy arrays. I keep getting the
error:
AttributeError: 'MaskedArray' object has no attribute 'typecode'
Of which I cannot find any good description. Can anybody suggest a reason?
Thanks in advance for any advice, I've pasted my code below,
Greg
Research Associate/GIS Manager
The Woods Hole Research Center
149 Woods Hole Road
Falmouth MA, 02540
508-540-9900x139
gfiske at whrc.org
http://whrc.org
-------------------------
import os, sys, glob
import gdal
import osr
import numpy as np
import numpy.ma as ma
mylist = glob.glob(indir + "Y*lengthgrowseas.img")
MyArrayList = []
increment = 0
def WriteRaster (dst_filename, raster):
format = "GTiff"
driver = gdal.GetDriverByName( format )
dst_ds = driver.Create( dst_filename, 1638, 660,1,gdal.GDT_Byte)
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326) #WGS84 lat long.
dst_ds.SetProjection( srs.ExportToWkt() )
dst_ds.GetRasterBand(1).WriteArray(raster)
dst_ds = None
for i in mylist:
increment = increment + 1
name, ext = i.split("ims/")
ext2, ext3 = ext.split(".")
dataset = gdal.Open(i)
a = dataset.ReadAsArray().astype(Numeric.Float32)
MyArrayList.append(a)
del a
b = np.vstack([MyArrayList])
c = np.ma.masked_array(b, -9999)
d = c.mean(axis=0)
WriteRaster("test.tif",d)
del i
More information about the gdal-dev
mailing list