-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnyc3dcars.py
158 lines (95 loc) · 3.72 KB
/
nyc3dcars.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# pylint: disable=W0232,R0903
# Most of these classes are fine as-is since sqlalchemy will modify them.
"""Manages access to nyc3dcars database."""
import warnings
from sqlalchemy import exc as sa_exc
from sqlalchemy import create_engine, MetaData, Column, Binary, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, deferred, scoped_session, sessionmaker
import os
import ConfigParser
warnings.simplefilter("ignore", category=sa_exc.SAWarning)
__config__ = ConfigParser.ConfigParser()
__config__.read(os.path.join(os.path.dirname(__file__), 'nyc3dcars.cfg'))
__username__ = __config__.get('database', 'username')
__password__ = __config__.get('database', 'password')
__dbname__ = __config__.get('database', 'name')
__host__ = __config__.get('database', 'host')
__port__ = __config__.getint('database', 'port')
__echo__ = __config__.getboolean('database', 'echo')
IMAGE_DIR = __config__.get('directories', 'image-dir')
__engine__ = create_engine(
'postgresql://%s:%s@%s:%d/%s' % (
__username__,
__password__,
__host__,
__port__,
__dbname__
),
echo=__echo__,
)
__metadata__ = MetaData(__engine__)
__Base__ = declarative_base(metadata=__metadata__)
class VehicleType(__Base__):
"""Sedan, minivan, etc."""
__tablename__ = 'vehicle_types'
__table_args__ = {'autoload': True}
detections = relationship('Detection', backref='vehicle_type')
vehicles = relationship('Vehicle', backref='vehicle_type')
class Detection(__Base__):
"""DPM detection result."""
__tablename__ = 'detections'
__table_args__ = {'autoload': True}
class Photo(__Base__):
"""Photograph along with geo-location data."""
__tablename__ = 'photos'
__table_args__ = {'autoload': True, 'extend_existing': True}
lla = deferred(Column('lla', Binary))
geom = deferred(Column('geom', Binary))
vehicles = relationship('Vehicle', backref='photo')
detections = relationship('Detection', backref='photo')
class Dataset(__Base__):
"""Contains the reconstruction correction factors."""
__tablename__ = 'datasets'
__table_args__ = {'autoload': True}
photos = relationship('Photo', backref='dataset')
class Vehicle(__Base__):
"""Ground truth vehicle annotation."""
__tablename__ = 'vehicles'
__table_args__ = {'autoload': True}
class Model(__Base__):
"""Registered DPM model."""
__tablename__ = 'models'
__table_args__ = {'autoload': True}
detections = relationship('Detection', backref='model')
class PlanetOsmLine(__Base__):
"""OpenStreetMap polylines. Roads, railways, etc."""
__tablename__ = 'planet_osm_line'
__table_args__ = {'autoload': True}
osm_id = Column(Integer, primary_key=True)
class Footprint(__Base__):
"""Building footprints from OpenData."""
__tablename__ = 'footprints'
__table_args__ = {'autoload': True}
class GeoidHeight(__Base__):
"""Distance used to turn ellipsoid height into orthometric height."""
__tablename__ = 'geoid_heights'
__table_args__ = {'autoload': True}
class Median(__Base__):
"""Road medians from OpenData."""
__tablename__ = 'medians'
__table_args__ = {'autoload': True}
class Roadbed(__Base__):
"""Roadbed polygons from OpenData."""
__tablename__ = 'roadbeds'
__table_args__ = {'autoload': True}
class Sidewalk(__Base__):
"""Sidewalk polygons from OpenData."""
__tablename__ = 'sidewalks'
__table_args__ = {'autoload': True}
class Elevation(__Base__):
"""Terrain elevation raster from USGS."""
__tablename__ = 'elevations'
__table_args__ = {'autoload': True}
__Base__.metadata.create_all(__engine__)
SESSION = scoped_session(sessionmaker(bind=__engine__))