Hello,
I'm trying to use the DTI wind speed ascii file which so many people have had problems with in the past. I'm using 10 and am unable to convert the ascii to vector. A number of years ago someone wrote a python script which was successful for others, but doesn't seem to work for me. No error message, just runs forever!
ASCII
The first row of the ascii point data looks like:
( 0, 1299); 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0;
the second row is:
(100, 1299); 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.
ORIGINAL SCRIPT
"""
dti_windspeed.py
Luke Pinner Nov 2006
Usage: python dti_windspeed.py infile outasc
infile = file containing DTI wind speed estimate data
outasc = new ascii grid format file suitable for import to grid using
"ASCII to Raster" tool
Notes: demo code only, no error handling at all...
all care, no responsibility etc...
"""
import sys, re
infile = sys.argv[1]
outasc = sys.argv[2]
rexp = re.compile(r'[\(\)]')
x=[]
y=[]
data=[]
file = open(infile, 'r+')
for line in file.readlines()[1:]: #Skip header
#format = (Easting, Northing) speed; speed; speed; etc.
line = rexp.sub('',line.strip().strip(';')).split(';')
xy=line.pop(0).split(',')
x.append(xy[0])
y.append(xy[1])
data.append(line)
file.close()
#x.sort()
#y.sort()
xmin = float(x[0])
xmax = float(x[-1]) + 100 #Eastings increment by 100 each line,
#largest x is start of line,
#x + 100 is the end of the line
ymin = float(y[-1])
ymax = float(y[0])+1
cellsize = 1000.0 #1km
ncols = str(int(xmax-xmin))
nrows = str(int(ymax-ymin))
#xllcorner = str(xmin-(cellsize/2)) #assumes given coordinates are for the cell centroid
#yllcorner = str(ymin-(cellsize/2)) #if not, use xllcorner = xmin etc. instead...
xllcorner = str(xmin) #assumes given coordinates are for the lower left corner of the cell
yllcorner = str(ymin) #if not, use xllcorner = str(xmin-(cellsize/2)) etc. instead...
asc = open(outasc, 'w+')
asc.write('ncols ' + ncols + '\n')
asc.write('nrows ' + nrows + '\n')
asc.write('xllcorner ' + xllcorner + '\n')
asc.write('yllcorner ' + yllcorner + '\n')
asc.write('cellsize ' + str(cellsize) + '\n')
asc.write('NODATA_value 0' + '\n')
for line in data: asc.write(' '.join(line) + '\n')
asc.flush()
asc.close()
#Done!
Any help would be greatly appreciated.
Thanks,
Najya