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

Revision 28280, 4.0 KB checked in by kdrangmeister, 2 years ago (diff)

it is a

  • 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        print "insert into planet_line_join (join_id, name, highway, way) values ('"+id+"','"+name+"','"+highway+"',SetSrid('"+way+"'::Text,4326));"
42        self.curs.execute("insert into planet_line_join (join_id, name, highway, way) values ('"+id+"','"+name+"','"+highway+"',SetSrid('"+way+"'::Text,4326))")
43
44    def what_is_it(self,geom):
45        result=[]
46        self.curs.execute("select astext(setsrid('"+geom+"'::Text,4326))")
47        result += self.curs.fetchall()
48        itisa=result[0][0]
49        itisa=itisa.split('(')[0]
50        print "whatisit-result = "+itisa
51        return itisa
52       
53       
54
55"""
56'Kittelstra\xc3\x9fe', '36717484,36717485,5627159'
57
58create table planet_line_join (join_id integer , name text, highway text);
59select AddGeometryColumn('planet_line_join', 'way', 4326, 'LINESTRING', 2 );
60
61"""
62
63def main(options):
64    bbox = options['bbox']
65    DSN = options['dsn']
66    print bbox
67    osmdb = JoinDB(DSN)
68    #highways = getHighwaysInBbox(DSN,bbox)
69    bxarray=bbox.split(",")
70    bbox="{b} {l},{t} {r}".format(b=bxarray[0],l=bxarray[1],t=bxarray[2],r=bxarray[3])
71    osmdb.set_bbox(bbox)
72    highways=osmdb.get_highways_segments()
73   
74    for hw in highways:
75        hwname = hw[0]
76        hwsegments = hw[1]
77        hwjoinedway = osmdb.get_joined_ways(hwsegments)
78        print "* Highway "+hwname+": "+hwjoinedway
79        osmdb.what_is_it(hwjoinedway)
80        osmdb.insert_joined_highway(str(0),hwname,"residential",hwjoinedway)
81#        break
82
83if __name__ == '__main__':
84    parser = OptionParser()
85    parser.add_option("-c", "--command", dest="command", help="The command to execute. Default is update. Possible values are update, install, clear", default="update")
86    parser.add_option("-b", "--bbox", dest="bbox", help="bounding box to restrict to", default="")
87    parser.add_option("-d", "--dsn", dest="dsn", help="DSN, default is 'dbname=gis host=crite'", default="dbname=gis host=crite")
88    (options, args) = parser.parse_args()
89    print options
90    main(options.__dict__)
91    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.