Exemple #1
0
class StreetTurnEvent:
    def __init__(self, osmdb_filename, timezone_name = "America/Los_Angeles"):
        self.osmdb = OSMDB( osmdb_filename )
        self.timezone_name = timezone_name
        
    @staticmethod
    def applies_to(edge1, vertex, edge2):
        return edge1 and edge2 and isinstance(edge1.payload, graphserver.core.Street) and isinstance(edge2.payload, graphserver.core.Street) \
               and edge1.payload.way != edge2.payload.way
    
    def __call__(self, edge1, vertex, edge2, context):
        
        osm_id = vertex.label.split("-")[1]
        
        # figure out which direction to turn
        osm_way_id1 = edge1.payload.name.split("-")[0]
        osm_way_id2 = edge2.payload.name.split("-")[0]
        
        osm_edge1 = self.osmdb.edge( edge1.payload.name )
        osm_edge2 = self.osmdb.edge( edge2.payload.name )
        
        osm_edge1_endnode = osm_edge1[3]
        osm_edge2_startnode = osm_edge2[2]
        
        osm_edge1_geom = osm_edge1[5]
        osm_edge2_geom = osm_edge2[5]
        
        if osm_id != osm_edge1_endnode:
            osm_edge1_geom.reverse()
             
        if osm_id != osm_edge2_startnode:
            osm_edge2_geom.reverse()
            
        endseg = osm_edge1_geom[-2:]
        startseg = osm_edge2_geom[:2]
        
        direction = turn_narrative( endseg[0], endseg[1], startseg[0], startseg[1] )
                
        street_name1 = self.osmdb.way( osm_way_id1 ).tags.get("name", "unnamed")
        street_name2 = self.osmdb.way( osm_way_id2 ).tags.get("name", "unnamed")
        
        osm_node_id, osm_node_tags, osm_node_lat, osm_node_lon, osm_node_refcount = self.osmdb.node( osm_id )
        
        average_speed = context['sumlength']/(vertex.state.time-context['lastturntime']) if vertex.state.time-context['lastturntime']>0 else 100000000
        what = "%s onto %s after %dm, %0.1fm rise, %0.1fm fall (%0.1fm/s)"%(direction, street_name2, context['sumlength'], context['sumrise'], context['sumfall'], average_speed)
        where = "%s & %s"%(street_name1, street_name2)
        when = "about %s"%str(TimeHelpers.unix_to_localtime( vertex.state.time, self.timezone_name ))
        geom = (osm_node_lon, osm_node_lat)
        
        context['sumlength'] = 0
        context['sumrise'] = 0
        context['sumfall'] = 0
        context['lastturntime'] = vertex.state.time
        return NarrativeEvent(what,where,when,geom)
Exemple #2
0
class StreetStartEvent:
    def __init__(self, osmdb_filename, timezone_name="America/Los_Angeles"):
        self.osmdb = OSMDB(osmdb_filename)
        self.timezone_name = timezone_name

    @staticmethod
    def applies_to(edge1, vertex, edge2):
        # if edge1 is not a street and edge2 is
        return (edge1 is None or not isinstance(edge1.payload, graphserver.core.Street)) and \
               (edge2 and isinstance(edge2.payload, graphserver.core.Street))

    def __call__(self, edge1, vertex, edge2, context):
        context['streetgeom'] = []
        context['sumlength'] = 0
        context['sumrise'] = 0
        context['sumfall'] = 0
        context['lastturntime'] = vertex.state.time

        osm_way2 = edge2.payload.name.split("-")[0]
        street_name2 = self.osmdb.way(osm_way2).tags.get('name', "unnamed")

        osm_id = vertex.label.split("-")[1]
        osm_node_id, osm_node_tags, osm_node_lat, osm_node_lon, osm_node_refcount = self.osmdb.node(
            osm_id)

        osm_edge2 = self.osmdb.edge(edge2.payload.name)
        osm_edge2_startnode = osm_edge2[2]
        osm_edge2_geom = osm_edge2[5]
        if osm_id != osm_edge2_startnode:
            osm_edge2_geom.reverse()
        startseg = osm_edge2_geom[:2]
        direction = description_from_north(startseg[0], startseg[1])

        what = "start walking"
        where = "on %s facing %s" % (street_name2, direction)
        when = "about %s" % str(
            TimeHelpers.unix_to_localtime(vertex.state.time,
                                          self.timezone_name))
        geom = [osm_node_lon, osm_node_lat]
        return NarrativeEvent(what, where, when, geom)
Exemple #3
0
class StreetEvent:
    def __init__(self, osmdb_filename, timezone_name="America/Los_Angeles"):
        self.osmdb = OSMDB( osmdb_filename )
        self.timezone_name = timezone_name
        
    @staticmethod
    def applies_to(vertex1, edge, vertex2):
        return edge is not None and isinstance(edge.payload, graphserver.core.Street)
    
    def __call__(self, vertex1, edge, vertex2, context):
        # adds to the variable set up by the StreetStartEvent
        geometry_chunk = self.osmdb.edge( edge.payload.name )[5]
        
        if len(context['streetgeom'])==0 or len(geometry_chunk)==0 or context['streetgeom'][-1] == geometry_chunk[0]:
            context['streetgeom'].extend( geometry_chunk )
        else:
            context['streetgeom'].extend( reversed( geometry_chunk ) )
            
        context['sumlength'] += edge.payload.length
        context['sumrise'] += edge.payload.rise
        context['sumfall'] += edge.payload.fall
        
        return None
Exemple #4
0
class StreetStartEvent:
    def __init__(self, osmdb_filename, timezone_name = "America/Los_Angeles"):
        self.osmdb = OSMDB( osmdb_filename )
        self.timezone_name = timezone_name
        
    @staticmethod
    def applies_to(edge1, vertex, edge2):
        # if edge1 is not a street and edge2 is
        return (edge1 is None or not isinstance(edge1.payload, graphserver.core.Street)) and \
               (edge2 and isinstance(edge2.payload, graphserver.core.Street))
    
    def __call__(self, edge1, vertex, edge2, context):
        context['streetgeom'] = []
        context['sumlength'] = 0
        context['sumrise'] = 0
        context['sumfall'] = 0
        context['lastturntime'] = vertex.state.time
        
        osm_way2 = edge2.payload.name.split("-")[0]
        street_name2 = self.osmdb.way( osm_way2 ).tags.get('name', "unnamed")
        
        osm_id = vertex.label.split("-")[1]
        osm_node_id, osm_node_tags, osm_node_lat, osm_node_lon, osm_node_refcount = self.osmdb.node( osm_id )
        
        osm_edge2 = self.osmdb.edge( edge2.payload.name )
        osm_edge2_startnode = osm_edge2[2]
        osm_edge2_geom = osm_edge2[5]
        if osm_id != osm_edge2_startnode:
            osm_edge2_geom.reverse()
        startseg = osm_edge2_geom[:2]
        direction = description_from_north( startseg[0], startseg[1] )
        
        what = "start walking"
        where = "on %s facing %s"%(street_name2, direction)
        when = "about %s"%str(TimeHelpers.unix_to_localtime( vertex.state.time, self.timezone_name ))
        geom = [osm_node_lon, osm_node_lat]
        return NarrativeEvent(what,where,when,geom)