File: compile_correction.py

package info (click to toggle)
twms 0.03e-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 424 kB
  • sloc: python: 1,527; sh: 111; makefile: 9
file content (41 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-
import os
import sys
from lxml import etree

tiles_cache = "/var/www/latlon/wms/cache/" 
layers = ["irs", "yhsat", "DGsat", "yasat","SAT"]
default_user = "Komzpa"
user = default_user
ts = ""

corr = sys.stdout
nodes = {}
curway = []
for lay in layers:
 print lay
 src = lay+".osm"
 if os.path.exists(src):
  corrfile = tiles_cache + lay+ "/rectify.txt"
  corr = open(corrfile, "w")
  context = etree.iterparse(open(src))
  for action, elem in context:
    items = dict(elem.items())
    ts = items.get("timestamp",ts)
    
 #   print items
    if elem.tag == "node":
       nodes[int(items["id"])] = (float(items["lon"]), float(items["lat"]))
    elif elem.tag == "nd":
       curway.append(nodes[int(items["ref"])])
    elif elem.tag == "tag":
       if items["k"] == "user":
         user = items["v"]
       if items["k"] == "timestamp":
         ts = items["v"]
    elif elem.tag == "way":
       ts = items.get("timestamp",ts)
       print >>corr, "%s %s %s %s %s %s"% (curway[0][0],curway[0][1],curway[1][0],curway[1][1], user, ts )
       curway = []
       user = default_user
       ts = ""