Gdal driver.Create TypeError

المشرف العام

Administrator
طاقم الإدارة
I have been writing a python script to convert an ascii grid into a geotiff file and when running the Create method in gdal i am receiving the following error message:

william@will-HP-EliteBook-850-G1:~/Smells$ python SmellsGeoTag.py ./SmellsTestData/test3/input/tile_1 ./output Traceback (most recent call last): File "SmellsGeoTag.py", line 47, in dst_ds = driver.Create(out , ncols, nrows, 1, gdal.GDT_Float32 ) File "/usr/local/lib/python2.7/dist-packages/GDAL-1.11.0-py2.7-linux-x86_64.egg/osgeo/gdal.py", line 394, in Create return _gdal.Driver_Create(self, *args, **kwargs) TypeError: in method 'Driver_Create', argument 3 of type 'int' however unlike the problem here my ncols and nrows values are non zero ints, so i am rather stumped as to what the problem is

source code:

#!/usr/bin/python import sys, getopt, os, numpy from osgeo import osr, gdal if len(sys.argv) != 3: print ("Please use the following arguements: input path, output path"); exit(); inRoot = sys.argv[1] outRoot = sys.argv[2] #finding valid files potentialDates = os.listdir(inRoot) dates = [] for i in potentialDates: if os.path.isdir(os.path.join(inRoot, i)): dates.append(i) for i in dates: potentialFiles = [] files = [] potentialFiles = os.listdir(os.path.join(inRoot, i)) for x in potentialFiles: if x.endswith(".asc"): files.append(x) #processing each valid file found for y in files: with open(os.path.join(inRoot, i, y), "r") as f: linelist = [line for line in f] junk, xllcorner = linelist.pop(0).split() float(xllcorner) junk, yllcorner = linelist.pop(0).split() float(yllcorner) junk, ncols = linelist.pop(0).split() int(ncols) junk, nrows = linelist.pop(0).split() int(nrows) junk, cellsize = linelist.pop(0).split() float(cellsize) junk, nodataval = linelist.pop(0).split() float(nodataval) data = [[float(digit) for digit in line.split()]for line in linelist] driver = gdal.GetDriverByName("GTiff") if not os.path.exists(os.path.join(outRoot,i)): os.makedirs(os.path.join(outRoot,i)) out = os.path.join(outRoot,i,y+".tif") dst_ds = driver.Create(out , ncols, nrows, 1, gdal.GDT_Float32 ) dst_ds.SetGeoTransform( [xllcorner,cellsize,0,yllcorner,0,cellsize] ) # set the reference info srs = osr.SpatialReference() srs.SetWellKnownGeogCS("WGS84") dst_ds.SetProjection( srs.ExportToWkt() ) # write the band dst_ds.GetRasterBand(1).WriteArray(data) exit()

أكثر...
 
أعلى