Exemplo n.º 1
0
def main():
    """Defines the simulation, map, monitors, persons. Connects POI with road network."""
    s = Simulation(geo=osm.OSMModel('../data/hannover2.osm'), rel_speed=30)
    # cafes are buildings and located in non_way_nodes --> filter that by tags
    cafes = [node for node in s.geo.non_way_nodes if "amenity" in node.tags and node.tags["amenity"] in ("bar","cafe","pub")]
    for cafe in cafes:
        # find nearest node to cafe
        dist = float('inf')
        nearest = None
        if not cafe.neighbors:
            for node in s.geo.way_nodes:
                d = utils.distance(cafe, node)
                if d < dist and node.neighbors:
                    dist = d
                    nearest = node
            # update neighbors
            cafe.neighbors[nearest] = int(dist)
            nearest.neighbors[cafe] = int(dist)
            cafe.n = [nearest]
            # update ways
            way = osm.WaySegment(cafe, nearest)
            cafe.ways[nearest] = way
            nearest.ways[cafe] = way
            s.geo.add(way)
            # add exit to cafe
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(PoiWiggler, 2, monitor=m, args={"cafes": cafes})
    s.run(until=10000, real_time=True, monitor=True)
Exemplo n.º 2
0
    def button_pressed(self, stage, event):
        """When mouse-button is pressed, find node that is closest to the
        mouse-pointer."""
        coords = self.actor.get_coords_from_event(event)
        coords_utm = latlong_to_utm(coords[1], coords[0])
        class Node:
            x = coords_utm[0]
            y = coords_utm[1]
        nearest = self.data.way_nodes[0]
        nearest_dist = utils.distance(Node, nearest)
        for node in self.data.way_nodes:
            if utils.distance(Node, node) < nearest_dist:
                nearest = node
                nearest_dist = utils.distance(Node, node)

        print
        print "==========KLICK=========="
        print nearest, nearest_dist
        print coords
        self.marker.set_position(nearest.lat, nearest.lon)