| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | from sqlalchemy import Column, ForeignKey |
|---|
| 15 | from sqlalchemy.types import Unicode, Integer, String, CHAR, Integer, Numeric, Float |
|---|
| 16 | |
|---|
| 17 | from bycycle.core.model import db |
|---|
| 18 | from bycycle.core.model.entities import base |
|---|
| 19 | from bycycle.core.model.entities.util import encodeFloat |
|---|
| 20 | from bycycle.core.model.data.sqltypes import POINT, LINESTRING |
|---|
| 21 | from bycycle.core.model.portlandor.data import SRID, slug |
|---|
| 22 | |
|---|
| 23 | from dijkstar import infinity |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | __all__ = ['PortlandORNode', 'PortlandOREdge'] |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | table_args = dict(schema='portlandor') |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | class 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 | |
|---|
| 45 | Node = PortlandORNode |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | class 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)) |
|---|
| 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 | |
|---|
| 84 | Edge = PortlandOREdge |
|---|