[OSGeo-Discuss] driver.create doesnot create a new object:Python

saksham_kumar sakkumarsak at gmail.com
Thu Jul 4 01:55:53 PDT 2013


Hi,
My Code is:
from mannkendall import kendall
import rankgiver, sorter
from osgeo import gdal

def performKendallTest(file_names,outer):
    n=len(file_names)
    row1=0
    col1=0
    datacube=[[] for m in range(0,n)]
    for m in range(0,n):
        dset=gdal.Open(file_names[m],gdal.GA_ReadOnly)
        r=dset.GetRasterBand(1)
        col1=dset.RasterXSize
        row1=dset.RasterYSize
        band=r.ReadAsArray(0,0,col1,row1)
        for i in range(0,row1):
            l=[[] for _ in range(0,col1)]
            try:
                l=band[i]
            except IndexError as e:
                pass
            datacube[m]=l
        null=r.GetNoDataValue()
    print datacube
    smap=[0 for _ in range(0,row1)]
    tmap=[0 for _ in range(0,row1)]
    zmap=[0 for _ in range(0,row1)]
    amap=[0 for _ in range(0,row1)]
    bmap=[0 for _ in range(0,row1)]
    for i in range(0,row1):
        l1=[0 for _ in range(0,col1)]
        l2=[0 for _ in range(0,col1)]
        l3=[0 for _ in range(0,col1)]
        l4=[0 for _ in range(0,col1)]
        l5=[0 for _ in range(0,col1)]
        for j in range(0,col1):
            l=[0 for o in range(0,n)]
            for k in range(0,n):
                try:
                    l[k]=datacube[i][j][k]
                except IndexError as ee:
                    pass
            res=kendall(range(1,n+1),l)
            l1[j]=res[0]
            l2[j]=res[1]
            l3[j]=res[2]
            l4[j]=res[3]
            l5[j]=res[4]
        smap[i]=l1
        tmap[i]=l2
        zmap[i]=l3
        amap[i]=l4
        bmap[i]=l5

    driver=gdal.GetDriverByName("JPEG")
    ss=outer+"_s.JPG"
    out=driver.Create(ss,col1,row1,1,gdal.GDT_Byte)
    out.SetGeoTransform(r.GetGeoTransform())
    out.SetProjection(r.GetProjection())
    o1=out.GetrasterBand(1)
    o1.SetNoDataValue(null)
    o1.WriteArray(smap)

    ss=outer+"_t.JPG"
    out=driver.Create(ss,col1,row1,1,gdal.GDT_Byte)
    out.SetGeoTransform(r.GetGeoTransform())
    out.SetProjection(r.GetProjection())
    o2=out.GetrasterBand(1)
    o2.SetNoDataValue(null)
    o2.WriteArray(tmap)
    
    ss=outer+"_z.JPG"
    out=driver.Create(ss,col1,row1,1,gdal.GDT_Byte)
    out.SetGeoTransform(r.GetGeoTransform())
    out.SetProjection(r.GetProjection())
    o3=out.GetrasterBand(1)
    o3.SetNoDataValue(null)
    o3.WriteArray(zmap)

    ss=outer+"_a.JPG"
    out=driver.Create(ss,col1,row1,1,gdal.GDT_Byte)
    out.SetGeoTransform(r.GetGeoTransform())
    out.SetProjection(r.GetProjection())
    o4=out.GetrasterBand(1)
    o4.SetNoDataValue(null)
    o4.WriteArray(amap)

    ss=outer+"_b.JPG"
    out=driver.Create(ss,col1,row1,1,gdal.GDT_Byte)
    out.SetGeoTransform(r.GetGeoTransform())
    out.SetProjection(r.GetProjection())
    o5=out.GetrasterBand(1)
    o5.SetNoDataValue(null)
    o5.WriteArray(bmap)
        
the problem it says is NoneType has no attribute SetGeoTransform.
when i tried to debug the code i found that the out object is not created.
My System is 32 bit windows XP.
Most Probably the create function is unable to create new Object.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/driver-create-doesnot-create-a-new-object-Python-tp5064013.html
Sent from the OSGeo Discuss mailing list archive at Nabble.com.



More information about the Discuss mailing list