source: subversion/applications/rendering/parking/joinways/joinways.py @ 28273

Revision 28273, 3.5 KB checked in by kdrangmeister, 2 years ago (diff)

fixed typo

  • Property svn:mime-type set to text/plain
Line 
1# -*- coding: utf-8 -*-
2# by kay
3
4import sys
5import string
6#import psycopg2
7from osmdb import OSMDB
8from optparse import OptionParser
9
10class JoinDB (OSMDB):
11
12    def get_highways_segments(self):
13        #self.curs.execute("SELECT osm_id,"+latlon+",\"parking:condition:"+side+":maxstay\","+coords+",'"+side+"' "+FW+" \"parking:condition:"+side+":maxstay\" is not NULL and \"parking:condition:"+side+"\"='disc'")
14        result=[]
15        #self.curs.execute("select osm_id,name from planet_line where \"way\" && SetSRID('BOX3D(1101474.25471931 6406603.879863935,1114223.324055468 6415715.307134068)'::box3d, 900913)")
16        print "result for bbox("+self.googbox+")"
17        print "select osm_id,name "+self.FlW+" \"way\" && "+self.googbox+""
18        #self.curs.execute("select osm_id,name from planet_line where \"way\" && "+self.googbox+"")
19        self.curs.execute("select name,string_agg(text(osm_id),',') from planet_line where highway is not Null and \"way\" && "+self.googbox+" and name is not Null group by name")
20        result += self.curs.fetchall()
21        highways=[]
22        for hw,osmids in result:
23            ids=osmids.split(',')
24            highways.append([hw,ids])
25       
26#        print "resultlen={l}".format(l=len(result))
27#        print "result={r}".format(r=result)
28        return highways
29
30    def get_joined_ways(self,segment_ids):
31        result=[]
32        self.curs.execute("select st_linemerge(st_collect(way)) "+self.FlW+" osm_id in ("+string.join(segment_ids,',')+");")
33        result += self.curs.fetchall()
34        print "jw-result = "+str(result)
35        return result[0][0]
36
37    def insert_joined_highway(self,id,name,highway,way):
38        #self.curs.execute("SELECT osm_id,"+latlon+",\"parking:condition:"+side+":maxstay\","+coords+",'"+side+"' "+FW+" \"parking:condition:"+side+":maxstay\" is not NULL and \"parking:condition:"+side+"\"='disc'")
39        result=[]
40        #self.curs.execute("select osm_id,name from planet_line where \"way\" && SetSRID('BOX3D(1101474.25471931 6406603.879863935,1114223.324055468 6415715.307134068)'::box3d, 900913)")
41        self.curs.execute("insert into planet_line_join (join_id, name, highway, way) values ("+id+","+name+","+highway+","+way+")")
42
43
44"""
45'Kittelstra\xc3\x9fe', '36717484,36717485,5627159'
46
47create table planet_line_join (join_id integer , name text, highway text, way geometry);
48
49"""
50
51def main(options):
52    bbox = options['bbox']
53    DSN = options['dsn']
54    print bbox
55    osmdb = JoinDB(DSN)
56    #highways = getHighwaysInBbox(DSN,bbox)
57    bxarray=bbox.split(",")
58    bbox="{b} {l},{t} {r}".format(b=bxarray[0],l=bxarray[1],t=bxarray[2],r=bxarray[3])
59    osmdb.set_bbox(bbox)
60    highways=osmdb.get_highways_segments()
61   
62    for hw in highways:
63        hwname = hw[0]
64        hwsegments = hw[1]
65        hwjoinedway = osmdb.get_joined_ways(hwsegments)
66        print "* Highway "+hwname+": "+hwjoinedway
67        osmdb.insert_joined_highway(0,hwname,"residential",hwjoinedway)
68        break
69
70if __name__ == '__main__':
71    parser = OptionParser()
72    parser.add_option("-c", "--command", dest="command", help="The command to execute. Default is update. Possible values are update, install, clear", default="update")
73    parser.add_option("-b", "--bbox", dest="bbox", help="bounding box to restrict to", default="")
74    parser.add_option("-d", "--dsn", dest="dsn", help="DSN, default is 'dbname=gis host=crite'", default="dbname=gis host=crite")
75    (options, args) = parser.parse_args()
76    print options
77    main(options.__dict__)
78    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.