root/Core/trunk/bycycle/core/model/portlandor/__init__.py

Revision 1160, 2.4 KB (checked in by wyatt, 3 years ago)

Added setuptools namespacing machinery and updated all imports accordingly.

  • Property svn:keywords set to Id
Line 
1###############################################################################
2# $Id$
3# Created 2005-11-07
4#
5# Portland, OR, region.
6#
7# Copyright (C) 2006-2008 Wyatt Baldwin, byCycle.org <wyatt@bycycle.org>.
8# All rights reserved.
9#
10# For terms of use and warranty details, please see the LICENSE file included
11# in the top level of this distribution. This software is provided AS IS with
12# NO WARRANTY OF ANY KIND.
13###############################################################################
14from sqlalchemy import Column, ForeignKey
15from sqlalchemy.types import Unicode, Integer, String, CHAR, Integer, Numeric, Float
16
17from bycycle.core.model import db
18from bycycle.core.model.entities import base
19from bycycle.core.model.entities.util import encodeFloat
20from bycycle.core.model.data.sqltypes import POINT, LINESTRING
21from bycycle.core.model.portlandor.data import SRID, slug
22
23from dijkstar import infinity
24
25
26__all__ = ['PortlandORNode', 'PortlandOREdge']
27
28
29table_args = dict(schema='portlandor')
30
31
32class PortlandORNode(base.Node):
33    __tablename__ = 'nodes'
34    __table_args__ = table_args
35    __mapper_args__ = dict(polymorphic_identity='portlandor_node')
36
37    id = Column(Integer, ForeignKey('public.nodes.id'), primary_key=True)
38    permanent_id = Column(Integer)
39    geom = Column(POINT(SRID))
40
41    @property
42    def edges(self):
43        return super(Node, self).edges
44
45Node = PortlandORNode
46
47
48class PortlandOREdge(base.Edge):
49    __tablename__ = 'edges'
50    __table_args__ = table_args
51    __mapper_args__ = dict(polymorphic_identity='portlandor_edge')
52
53    id = Column('id', Integer, ForeignKey('public.edges.id'), primary_key=True)
54    geom = Column(LINESTRING(SRID))
55    permanent_id = Column(Numeric(11, 2))
56    code = Column(Integer)
57    bikemode = Column(CHAR(1))  # enum('','p','t','b','l','m','h','c','x')
58    up_frac = Column(Float)
59    abs_slope = Column(Float)
60    cpd = Column(Integer)
61    sscode = Column(Integer)
62
63    def to_feet(self):
64        return self.geom.length
65
66    def to_miles(self):
67        return self.to_feet() / 5280.0
68
69    def to_kilometers(self):
70        return self.to_miles() * 1.609344
71
72    def to_meters(self):
73        return self.to_kilometers() * 1000.0
74
75    @classmethod
76    def _adjustRowForMatrix(cls, row):
77        adjustments = {
78            'length': encodeFloat(row.geom.length / 5280.0),
79            'abs_slope': encodeFloat(row.abs_slope),
80            'up_frac': encodeFloat(row.up_frac),
81        }
82        return adjustments
83
84Edge = PortlandOREdge
Note: See TracBrowser for help on using the browser.