Пример #1
0
    def __init__(self, osmfile):
        # parse the input file and save its contents in memory

        # initialize street network
        self.street_network = StreetNetwork()

        # coord pairs as returned from imposm
        self.coords = dict()

        # max and min latitude and longitude
        self.bounds = dict()
        self.bounds["min_lat"] = 9999
        self.bounds["max_lat"] = -9999
        self.bounds["min_lon"] = 9999
        self.bounds["max_lon"] = -9999

        # active copy of OSM data indexed by OSM id
        self.all_osm_relations = dict()
        self.all_osm_ways = dict()
        self.all_osm_nodes = dict()

        # nodes with specific landuse tags
        self.residential_nodes = set()
        self.industrial_nodes = set()
        self.commercial_nodes = set()

        # subset that is also connected to the street network
        self.connected_residential_nodes = set()
        self.connected_industrial_nodes = set()
        self.connected_commercial_nodes = set()

        # mapping from highway types to max speeds
        # we do this so there"s always a speed limit for every edge, even if
        # none is in the OSM data
        self.max_speed_map = dict()
        self.max_speed_map["motorway"] = 140
        self.max_speed_map["trunk"] = 120
        self.max_speed_map["primary"] = 100
        self.max_speed_map["secondary"] = 80
        self.max_speed_map["tertiary"] = 70
        self.max_speed_map["road"] = 50
        self.max_speed_map["minor"] = 50
        self.max_speed_map["unclassified"] = 50
        self.max_speed_map["residential"] = 30
        self.max_speed_map["track"] = 30
        self.max_speed_map["service"] = 20
        self.max_speed_map["path"] = 10
        self.max_speed_map["cycleway"] = 1   # >0 to prevent infinite weights
        self.max_speed_map["bridleway"] = 1  # >0 to prevent infinite weights
        self.max_speed_map["pedestrian"] = 1 # >0 to prevent infinite weights
        self.max_speed_map["footway"] = 1    # >0 to prevent infinite weights

        p = OSMParser(concurrency = 1,
                      coords_callback = self.coords_callback,
                      nodes_callback = self.nodes_callback,
                      ways_callback = self.ways_callback,
                      relations_callback = self.relations_callback)
        p.parse(osmfile)
Пример #2
0
    potential_speed = sqrt(settings["braking_deceleration"] *
                           available_braking_distance * 2)  # m/s
    # cars respect speed limit
    actual_speed = min(max_speed, potential_speed * 3.6)  # km/h

    return actual_speed


if __name__ == "__main__":

    def out(*output):
        for o in output:
            print o,
        print ''

    street_network = StreetNetwork()
    street_network.add_node(1, 0, 0)
    street_network.add_node(2, 0, 0)
    street_network.add_node(3, 0, 0)
    street_network.add_street((
        1,
        2,
    ), 10, 50)
    street_network.add_street((
        2,
        3,
    ), 100, 140)

    trips = dict()
    trips[1] = [3]