-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasc_reader.py
More file actions
58 lines (40 loc) · 1.52 KB
/
asc_reader.py
File metadata and controls
58 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys, os, datetime, string
import sqlite3 as db
# -- globalis kornyezeti valtozok, ezek modosithatok:
PTH_WORK = 'D:/work/'
DSS_BTON = 'Balaton-2013.dss'
DSS_ZALA = 'zala.dss'
conn = db.connect(PTH_WORK + 'FTP2DSS/ftpimport.sqlite')
curs = conn.cursor()
stmt_ins = "INSERT INTO ftpadat (easting, northing, element, data, timestamp) VALUES (?,?,?,?,?)"
os.chdir (PTH_WORK + '/asc')
filelist = [ f for f in os.listdir(".") ]
filelist.sort()
for f in filelist:
colno = 0
rowno = 0
c = f[3:-34]
m = f[-14:-4]
ascfile = open('%s' % f)
ncols = string.atof(string.split(ascfile.readline(), " ")[1])
nrows = string.atof(string.split(ascfile.readline(), " ")[1])
xllcnt = string.atof(string.split(ascfile.readline(), " ")[1])
yllcnt = string.atof(string.split(ascfile.readline(), " ")[1])
csize = string.atof(string.split(ascfile.readline(), " ")[1])
nodata = string.split(ascfile.readline(), " ")[1]
curX = xllcnt
curY = yllcnt + csize * (nrows - 1) # mert nem bal also, hanem bal felso !!!
for coordinates in ascfile:
for s in string.split(coordinates, " "):
e = curX + csize * colno
n = curY - csize * rowno
curs.execute(stmt_ins, (e, n, c, string.atof(s), m))
colno += 1
if colno == ncols:
colno = 0
rowno += 1
ascfile.close()
print " *** '%s' feldolgozva." % f
curs.close()
conn.commit()
conn.close()