예제 #1
0
def test_live():
    # Clear tilescache
    shutil.rmtree("tilescache")

    # Do some routing - a car test
    r = pyroutelib3.Router("car")
    a, b = r.findNode(52.240712, 21.025801), r.findNode(52.2462868, 21.0123011)
    s, t = r.doRoute(a, b)

    assert s == "success"
    assert len(r.routing) < 15_000

    # Do some routing - a bus test
    r = pyroutelib3.Router("bus")
    a, b = r.findNode(52.240712, 21.025801), r.findNode(52.2462868, 21.0123011)
    s, t = r.doRoute(a, b)

    assert s == "success"
    assert len(r.routing) < 7500

    # Do some routing - a tram test
    r = pyroutelib3.Router("tram")
    a, b = r.findNode(52.244585, 21.084751), r.findNode(52.225889, 20.996075)
    s, t = r.doRoute(a, b)

    assert s == "success"
    assert len(r.routing) < 1500

    # Count up the number of tiles
    count = 0
    for (dirpath, dirnames, fnames) in os.walk("tilescache"):
        for f in fnames:
            if f == "data.osm": count += 1

    assert count < 30
예제 #2
0
def test_live():
    # # Clear tilescache
    # shutil.rmtree("tilescache")

    # Do some routing - a car test
    r = pyroutelib3.Router("car")
    a, b = r.findNode(52.240712, 21.025801), r.findNode(52.2462868, 21.0123011)
    s, t = r.doRoute(a, b)

    assert s == "success"
    assert len(r.routing) < 15_000

    # Do some routing - a bus test
    r = pyroutelib3.Router("bus")
    a, b = r.findNode(52.240712, 21.025801), r.findNode(52.2462868, 21.0123011)
    s, t = r.doRoute(a, b)

    assert s == "success"
    assert len(r.routing) < 7500

    # Do some routing - a tram test
    r = pyroutelib3.Router("tram")
    a, b = r.findNode(52.244585, 21.084751), r.findNode(52.225889, 20.996075)
    s, t = r.doRoute(a, b)

    assert s == "success"
    assert len(r.routing) < 1500
예제 #3
0
def test_no_prints(capsys):
    r = pyroutelib3.Router("car", "tests/simple_graph.osm")
    r.doRoute(-1, -8)

    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
예제 #4
0
def test_shortest_not_optimal():
    r = pyroutelib3.Router("car", distFunction=pyroutelib3.distEuclidian)
    r.localFile = True

    # Nodes
    r.rnodes[1] = (0, 0)
    r.rnodes[2] = (1, 0)
    r.rnodes[3] = (2, 0)
    r.rnodes[4] = (0, 1)
    r.rnodes[5] = (1, 1)
    r.rnodes[6] = (2, 1)
    r.rnodes[7] = (0, 2)
    r.rnodes[8] = (1, 2)
    r.rnodes[9] = (2, 2)

    # Edges
    r.routing[1] = {2: 1, 4: 6}
    r.routing[2] = {1: 1, 3: 2, 5: 5}
    r.routing[3] = {2: 2, 6: 1}
    r.routing[4] = {1: 6, 5: 2, 7: 4}
    r.routing[5] = {2: 5, 4: 2, 6: 4, 8: 3}
    r.routing[6] = {3: 1, 5: 4, 9: 1}
    r.routing[7] = {4: 4, 8: 5}
    r.routing[8] = {5: 3, 7: 5, 9: 1}
    r.routing[9] = {6: 1, 8: 1}

    # do the route
    s, n = r.doRoute(1, 8)
    assert s == "success"
    assert n == [1, 2, 3, 6, 9, 8]
예제 #5
0
파일: map.py 프로젝트: carloj123/MASiRe
 def __init__(self, map_config, proximity, movement_restrictions):
     map_location = str(
         (pathlib.Path(__file__).parents[4] / map_config['osm']).absolute())
     self.router = pyroutelib3.Router("car", map_location)
     self.measure_unit = 100000
     self.proximity = proximity / self.measure_unit
     self.map_config = map_config
     self.movement_restrictions = movement_restrictions
예제 #6
0
def test_mik4():
    r = pyroutelib3.Router("bus", "tests/test_mikolajki.osm")
    a, b = r.findNode(53.799199,
                      21.5726826), r.findNode(53.7926757, 21.5732485)
    s, t = r.doRoute(a, b)

    assert a == -102326
    assert b == -102604
    assert s == "success"
    assert t == mik4_correct
예제 #7
0
def test_routing():
    "Test routing."

    import pyroutelib3

    router = pyroutelib3.Router('car')
    start = router.findNode(52.523427, 13.413677)  # Alex
    end = router.findNode(52.516121, 13.38003)  # Adlon

    status, route = router.doRoute(start, start)
    assert (status, route) == ('no_route', [])
예제 #8
0
    def create_router(self):
        print("\033[1A\033[K" + "Creating shape generator")
        request = requests.get(r"https://overpass-api.de/api/interpreter/?data=%5Bbbox%3A54.32%2C18.21%2C54.65%2C18.61%5D%5Bout%3Axml%5D%3B%0A(%0A%20way%5B%22highway%22%3D%22motorway%22%5D%3B%0A%20way%5B%22highway%22%3D%22motorway_link%22%5D%3B%0A%20way%5B%22highway%22%3D%22trunk%22%5D%3B%0A%20way%5B%22highway%22%3D%22trunk_link%22%5D%3B%0A%20way%5B%22highway%22%3D%22primary%22%5D%3B%0A%20way%5B%22highway%22%3D%22primary_link%22%5D%3B%0A%20way%5B%22highway%22%3D%22secondary%22%5D%3B%0A%20way%5B%22highway%22%3D%22secondary_link%22%5D%3B%0A%20way%5B%22highway%22%3D%22tertiary%22%5D%3B%0A%20way%5B%22highway%22%3D%22tertiary_link%22%5D%3B%0A%20way%5B%22highway%22%3D%22unclassified%22%5D%3B%0A%20way%5B%22highway%22%3D%22minor%22%5D%3B%0A%20way%5B%22highway%22%3D%22residential%22%5D%3B%0A%20way%5B%22highway%22%3D%22living_street%22%5D%3B%0A%20way%5B%22highway%22%3D%22service%22%5D%3B%0A)%3B%0A%3E-%3E.n%3B%0A%3C-%3E.r%3B%0A(._%3B.n%3B.r%3B)%3B%0Aout%3B%0A")

        temp_xml = NamedTemporaryFile(delete=False)
        temp_xml.write(request.content)
        temp_xml.seek(0)

        self.router = pyroutelib3.Router("bus", temp_xml.name)

        temp_xml.close()
예제 #9
0
파일: map.py 프로젝트: carloj123/MASiRe
    def restart(self, map_config, proximity, movement_restrictions):
        """Restart the map by reseting all the variables and also deleting the router from memory to prevent errors.

        :param map_config: The location of the file with the osm map.
        :param proximity: The proximity allowed by the user to someone be considered on the same place as anotherone.
        :param movement_restrictions: Movement restrictions of the environment."""

        del self.router
        map_location = str(
            (pathlib.Path(__file__).parents[4] / map_config['osm']).absolute())
        self.router = pyroutelib3.Router("car", map_location)
        self.measure_unit = 100000
        self.proximity = proximity / self.measure_unit
        self.map_config = map_config
        self.movement_restrictions = movement_restrictions
예제 #10
0
def prepare_router():
    r = pyroutelib3.Router("car", distFunction=pyroutelib3.distEuclidian)
    r.localFile = True

    r.rnodes[1] = (1, 1)
    r.rnodes[2] = (2, 1)
    r.rnodes[3] = (3, 1)
    r.rnodes[4] = (4, 1)
    r.rnodes[5] = (3, 0)

    r.routing[1] = {2: 2}
    r.routing[2] = {1: 2, 3: 2, 5: 1}
    r.routing[3] = {2: 2, 4: 2}
    r.routing[4] = {3: 2, 5: 2}
    r.routing[5] = {2: 1, 4: 1}

    return r
예제 #11
0
def prepare_router():
    r = pyroutelib3.Router("car")
    r.localFile = True
    r.distance = math.dist

    r.rnodes[1] = (1, 1)
    r.rnodes[2] = (2, 1)
    r.rnodes[3] = (3, 1)
    r.rnodes[4] = (4, 1)
    r.rnodes[5] = (3, 0)

    r.routing[1] = {2: 2}
    r.routing[2] = {1: 2, 3: 2, 5: 1}
    r.routing[3] = {2: 2, 4: 2}
    r.routing[4] = {3: 2, 5: 2}
    r.routing[5] = {2: 1, 4: 1}

    return r
예제 #12
0
def test_processing():
    r = pyroutelib3.Router("car", "tests/simple_graph.osm", "xml")

    # The graph looks like this:
    #   9
    #   │         8
    #  ┌63┐       │
    # 60  62──────7
    #  └61┘      /│\
    #   │       4 │ 5
    #   │        \│/
    #   2─────────3
    #   │
    #   1

    assert len(r.rnodes) == 12, "incorrect amount of nodes in Graph"

    # cost  -1 -2: ~104.051
    assert 0.1403 < r.routing[-1][-2] < 0.1404, "invalid cost calculation"
    assert r.routing[-1][-2] == r.routing[-2][-1], "cost different in 2 ways"

    # cost -62 -7: ~204.08
    assert 0.2038 < r.routing[-62][-7] < 0.2039, "cost calculation invalid"

    # oneway:  -4 →  -3 →  -5 →  -7 →  -4
    assert -3 in r.routing[-4], "invalid oneway handling"
    assert -5 in r.routing[-3], "invalid oneway handling"
    assert -7 in r.routing[-5], "invalid oneway handling"
    assert -4 in r.routing[-7], "invalid oneway handling"

    assert -7 not in r.routing[-4], "invalid oneway handling"
    assert -5 not in r.routing[-7], "invalid oneway handling"
    assert -3 not in r.routing[-5], "invalid oneway handling"
    assert -4 not in r.routing[-3], "invalid oneway handling"

    # roundabout: -60 → -61 → -62 → -63 → -60
    assert -61 in r.routing[-60], "invalid oneway handling"
    assert -62 in r.routing[-61], "invalid oneway handling"
    assert -63 in r.routing[-62], "invalid oneway handling"
    assert -60 in r.routing[-63], "invalid oneway handling"

    assert -60 not in r.routing[-61], "invalid oneway handling"
    assert -61 not in r.routing[-62], "invalid oneway handling"
    assert -62 not in r.routing[-63], "invalid oneway handling"
    assert -63 not in r.routing[-60], "invalid oneway handling"

    # -2 ↔ -61 motor_vehicle=no
    assert -2 not in r.routing[-61], "invalid access tag handling"
    assert -61 not in r.routing[-2], "invalid access tag handling"

    # no -8 -7 -3 (-200)
    assert (-8, -7,
            -3) in r.forbiddenMoves, "invlaid no_* restriction handling"

    # no -7 -3 -5 (-201) except car
    assert (
        -7, -3, -5
    ) not in r.forbiddenMoves, "invalid except=* in restrictions handling"

    # only -1 -2 -3 (-201)
    assert r.mandatoryMoves[(-1,
                             -2)] == [-3
                                      ], "invalid only_* restriction handling"
예제 #13
0
    def create_router(transport):
        print("\033[1A\033[K" + "Creating shaper for {}".format(transport))
        if transport == "bus":
            routing_type = {
                "weights": {"motorway": 1.5, "trunk": 1.5, "primary": 1.4, "secondary": 1.3, "tertiary": 1.3,
                "unclassified": 1, "residential": 0.6, "living_street": 0.6, "track": 0.3, "service": 0.5},
                "access": ["access", "vehicle", "motor_vehicle", "psv", "bus", "routing:ztm"],
                "name": "bus"
            }
        elif transport == "train":
            routing_type = "train"
        elif transport == "tram":
            routing_type = "tram"
        else:
            raise ValueError("Invalid transport type {} for Shaper".format(transport))

        if transport in {"train", "tram"}:
            request = requests.get("https://mkuran.pl/feed/ztm/ztm-km-rail-shapes.osm", stream=True)

        else:
            # Overpass Query:
            query = "\n".join([
                "[bbox:51.9144,20.4438,52.5007,21.4844][out:xml];"
                "("
                ' way["highway"="motorway"];'
                ' way["highway"="motorway_link"];'
                ' way["highway"="trunk"];'
                ' way["highway"="trunk_link"];'
                ' way["highway"="primary"];'
                ' way["highway"="primary_link"];'
                ' way["highway"="secondary"];'
                ' way["highway"="secondary_link"];'
                ' way["highway"="tertiary"];'
                ' way["highway"="tertiary_link"];'
                ' way["highway"="unclassified"];'
                ' way["highway"="minor"];'
                ' way["highway"="residential"];'
                ' way["highway"="living_street"];'
                ' way["highway"="service"];'
                ');'
                'way._(poly:"52.4455 20.6858 52.376 20.6872 52.3533 20.7868 52.2929 20.726 52.2694 20.6724 52.2740 20.4465 52.2599 20.4438 52.2481 20.5832 52.2538 20.681 52.1865 20.6786 52.1859 20.7129 52.1465 20.7895 52.0966 20.783 52.0632 20.7222 52.0151 20.7617 51.9873 20.9351 51.9269 20.9509 51.9144 21.0226 51.9322 21.1987 51.9569 21.2472 52.0463 21.2368 52.1316 21.4844 52.1429 21.4404 52.2130 21.3814 52.2622 21.3141 52.2652 21.1977 52.3038 21.173 52.3063 21.2925 52.3659 21.3515 52.3829 21.3001 52.4221 21.1929 52.4898 21.1421");'
                '>->.n;'
                '<->.r;'
                '(._;.n;.r;);'
                'out;'
            ])

            request = requests.get(
                "https://overpass-api.de/api/interpreter/",
                params={"data": query},
                stream=True,
            )

        temp_xml = NamedTemporaryFile(delete=False)

        for chunk in request.iter_content(chunk_size=1024):
            temp_xml.write(chunk)

        request.close()
        temp_xml.seek(0)

        router = pyroutelib3.Router(routing_type, temp_xml.name)

        temp_xml.close()

        return router
예제 #14
0
import pyroutelib3
import os
import smopy
import matplotlib.pyplot as plt

if __name__ == '__main__':
    start = (42.32683295, -71.61669892134148)
    dest = (42.3185910, -71.6448530)

    r = pyroutelib3.Router("car")

    a, b = r.findNode(start[0], start[1]), r.findNode(dest[0], dest[1])
    s, path = r.doRoute(a, b)
    rnodes = r.get_rnodes()

    lat_min = min(start[0], dest[0])
    lat_max = max(start[0], dest[0])
    long_min = min(start[1], dest[1])
    long_max = max(start[1], dest[1])
    map = smopy.Map((lat_min, long_min, lat_max, long_max))
    x_markers = []
    y_markers = []

    for node in path:
        x, y = rnodes[node]
        x, y = map.to_pixels(x, y)
        x_markers.append(x)
        y_markers.append(y)
    ax = map.show_mpl(figsize=(8, 6))
    x, y = map.to_pixels(start[0], start[1])
    x1, y1 = map.to_pixels(dest[0], dest[1])