コード例 #1
0
    def road_ends_in_intersection_city(self):
        """
        When using smooth geometries, the original intersection point (0,0) does
        not exist anymore as a place for the roads to intersect (it should be
        replaced by an arc or similar). Since s2 dies on (0,0) the road geometry
        has to be extended to touch the new s1 geometry.

                             __--- (50,30)
        (-50,0) ------- + ---
                        |
                        |
                      (0,-50)
        """
        city = City("Road ends in intersection")

        s1 = Street.from_control_points([Point(-50, 0), Point(0, 0), Point(50, 30)])
        s1.name = "s1"

        s2 = Street.from_control_points([Point(0, -50), Point(0, 0)])
        s2.name = "s2"

        city.add_intersection_at(Point(0, 0))

        city.add_road(s1)
        city.add_road(s2)

        return city
コード例 #2
0
    def Y_intersection_one_to_many_city(self):
        """
                  (0,100)
                    |
                    |
                    +
                   / \
                  /   \
         (-100,-100) (100,-100)
        """
        city = City("Y intersection - One to many")

        s1 = Street.from_control_points([Point(0, 100), Point(0, 0)])
        s1.name = "s1"

        s2 = Street.from_control_points([Point(0, 0), Point(-100, -100)])
        s2.name = "s2"

        s3 = Street.from_control_points([Point(0, 0), Point(100, -100)])
        s3.name = "s3"

        city.add_intersection_at(Point(0, 0))

        city.add_road(s1)
        city.add_road(s2)
        city.add_road(s3)

        return city
コード例 #3
0
    def test_malformed_paths(self):
        with self.assertRaises(ValueError):
            lane = Street.from_control_points([]).lane_at(0)
            geometry = lane.path_for(PolylineGeometry)

        with self.assertRaises(ValueError):
            lane = Street.from_control_points([Point(0, 0)]).lane_at(0)
            geometry = lane.path_for(PolylineGeometry)
コード例 #4
0
 def test_line_interpolation_points_multiple_segments_path(self):
     points = self._road_points()
     tuples = map(lambda point: point.to_tuple(), points)
     lane = Street.from_control_points(points).lane_at(0)
     geometry = lane.path_for(PolylineGeometry)
     interpolation_points = geometry.line_interpolation_points()
     self.assertEquals(interpolation_points, points)
コード例 #5
0
    def trunk_from_street_city(self):
        """
         ---<---
               +---<---
         --->--+
        """
        city = City("Trunk from street")

        trunk = Trunk.from_control_points([
            Point(0, 0),
            Point(50, 0)
        ])
        trunk.name = "t1"

        street = Street.from_control_points([
            Point(100, 0),
            Point(50, 0)
        ])
        street.name = "s1"

        city.add_road(trunk)
        city.add_road(street)

        city.add_intersection_at(Point(50, 0))

        return city
コード例 #6
0
 def test_elements_single_segment_path(self):
     a = Point(0, 0)
     b = Point(50, -50)
     lane = Street.from_control_points([a, b]).lane_at(0)
     geometry = lane.path_for(LinesAndArcsGeometry)
     expected_elements = [LineSegment(a, b)]
     self.assertAlmostEqual(geometry.elements(), expected_elements)
コード例 #7
0
    def test_elements_heading_signle_segment_path(self):
        a = Point(0, 0)
        b = Point(50, -50)

        lane = Street.from_control_points([a, b]).lane_at(0)
        geometry = lane.path_for(LinesAndArcsGeometry)
        elements = geometry.elements()

        self.assertAlmostEqual(geometry.elements()[0].start_heading(), -45)
        self.assertAlmostEqual(geometry.elements()[0].end_heading(), -45)
コード例 #8
0
    def test_get_roads_V_type(self):
        """
        (0,0)--(3,1)
          |----(3,-1)
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(3, 1))
        n3 = GraphNode(Point(3, -1))

        self._connect(n1, n2)
        self._connect(n1, n3)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3]).run()
        intersection = RoadIntersectionNode.on(0, 0)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(3, 1), intersection]),
            Street.from_nodes([RoadSimpleNode.on(3, -1), intersection])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
コード例 #9
0
 def simple_street_city(self):
     city = City("Single street")
     street = Street.from_control_points([
         Point(0, 0),
         Point(100, 0),
         Point(200, 0)
     ])
     street.name = "s1"
     city.add_road(street)
     return city
コード例 #10
0
 def test_elements_multiple_segments_path(self):
     [a, b, c, d] = self._road_points()
     lane = Street.from_control_points([a, b, c, d]).lane_at(0)
     geometry = lane.path_for(PolylineGeometry)
     expected_elements = [
         LineSegment(a, b),
         LineSegment(b, c),
         LineSegment(c, d)
     ]
     self.assertEquals(geometry.elements(), expected_elements)
コード例 #11
0
    def test_elements_heading_two_collinear_segment_path(self):
        a = Point(0, 0)
        b = Point(50, 50)
        c = Point(100, 100)

        lane = Street.from_control_points([a, b, c]).lane_at(0)
        geometry = lane.path_for(LinesAndArcsGeometry)
        elements = geometry.elements()

        self.assertAlmostEqual(elements[0].start_heading(), 45)
        self.assertAlmostEqual(elements[0].end_heading(), 45)
コード例 #12
0
    def T_intersection_out_city(self):
        """
        (-100,0) -- + -- (100,0)
                    |
                  (0,-100)
        """
        city = City("T intersection out")

        s1 = Street.from_control_points([Point(-100, 0), Point(0, 0), Point(100, 0)])
        s1.name = "s1"

        s2 = Street.from_control_points([Point(0, 0), Point(0, -100)])
        s2.name = "s2"

        city.add_intersection_at(Point(0, 0))

        city.add_road(s1)
        city.add_road(s2)

        return city
コード例 #13
0
    def L_intersection_city(self):
        """
            (0,100)
               |
               + -- (100,0)
        """
        city = City("L intersection")

        s1 = Street.from_control_points([Point(0, 100), Point(0, 0)])
        s1.name = "s1"

        s2 = Street.from_control_points([Point(0, 0), Point(100, 0)])
        s2.name = "s2"

        city.add_intersection_at(Point(0, 0))

        city.add_road(s1)
        city.add_road(s2)

        return city
コード例 #14
0
    def two_non_collinear_segments_less_than_border_city(self):
        """
        (-10,0) -- (0,0) -- (10,2) -- (20,4)
        """
        city = City("Non collinear segments - Less than border")

        s1 = Street.from_control_points([Point(-10, 0), Point(0, 0), Point(4, 2), Point(20, 7)])
        s1.name = "s1"

        city.add_road(s1)

        return city
コード例 #15
0
    def non_collinear_segments_city(self):
        """
        (-100,0) -- (0,0) -- (100,30)
        """
        city = City("Non collinear segments - Standard")

        s1 = Street.from_control_points([Point(-100, 0), Point(0, 0), Point(100, 30)])
        s1.name = "s1"

        city.add_road(s1)

        return city
コード例 #16
0
    def run(self):
        to_traverse = self.graph_node_list
        for node in to_traverse:
            node.prepare_traversal()
        while to_traverse:
            # Not particularly performant, needs review
            to_traverse = sorted(
                to_traverse,
                key=lambda node: node.neighbours_to_traverse_count())
            node = to_traverse.pop(0)
            while node.get_neighbours_to_traverse():
                # Revert this commented code once we support trunks in monolane
                # generator
                if node.is_minor_road:
                    road = Street()
                else:
                    road = Trunk()
                if node.neighbours_count() > 1:
                    self.city.add_intersection_at(node.location)

                road.add_control_point(node.location)

                self._build_road(road, None, node)

                if road.node_count() > 1:
                    self.city.add_road(road)
コード例 #17
0
    def test_get_roads_multiple_non_aligned_segments(self):
        """
        (0,0)--(1,0)--(5,1)--(6,2)
        Note that the last 2 segments have a 45deg angle
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(5, 1))
        n4 = GraphNode(Point(6, 2))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n3, n4)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4]).run()

        intersection = RoadIntersectionNode.on(5, 1)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), RoadSimpleNode.on(1, 0), intersection]),
            Street.from_nodes([RoadSimpleNode.on(6, 2), intersection])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
コード例 #18
0
    def test_get_roads_L_type(self):
        """
        (0,0)--(1,0)--(6,1)
                  |---(6,6)
        Note that (6,6) is discarded since the angle is greater than 15deg
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(6, 1))
        n4 = GraphNode(Point(6, 6))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n2, n4)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4]).run()
        intersection = RoadIntersectionNode.on(1, 0)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), intersection, RoadSimpleNode.on(6, 1)]),
            Street.from_nodes([RoadSimpleNode.on(6, 6), intersection])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
コード例 #19
0
    def test_get_roads_multiple_independent_segments(self):
        """
        (0,0)--(1,0)--(6,1)
        (2,5)--(3,4)
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(6, 1))
        n4 = GraphNode(Point(2, 5))
        n5 = GraphNode(Point(3, 4))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n4, n5)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4, n5]).run()

        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), RoadSimpleNode.on(1, 0), RoadSimpleNode.on(6, 1)]),
            Street.from_nodes([RoadSimpleNode.on(2, 5), RoadSimpleNode.on(3, 4)])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
コード例 #20
0
    def _create_road(self, city, osm_id, geometry, is_one_way, is_reversed,
                     is_trunk):
        if is_trunk:
            road = Trunk(name='OSM_' + osm_id)
        else:
            road = Street(name='OSM_' + osm_id)

        if is_reversed:
            geometry = geometry.reversed()

        road.add_control_points(geometry.vertices())

        city.add_road(road)
コード例 #21
0
ファイル: street_test.py プロジェクト: rachillesf/terminus
 def test_accept(self):
     street = Street()
     street.get_nodes = mock.Mock(return_value=[])
     street.lanes = mock.Mock(return_value=[])
     generator_mock = mock.Mock()
     calls = [mock.call.start_street(street), mock.call.end_street(street)]
     street.accept(generator_mock)
     generator_mock.assert_has_calls(calls)
コード例 #22
0
    def test_elements_two_non_collinear_segment_path(self):
        a = Point(0, 0)
        b = Point(50, 0)
        c_up = Point(100, 10)
        c_down = Point(100, -10)

        lane = Street.from_control_points([a, b, c_up]).lane_at(0)
        geometry = lane.path_for(LinesAndArcsGeometry)

        expected_elements = [
            LineSegment(a, Point(45.0, 0.0)),
            Arc(Point(45.0, 0.0), 0.0, 50.49509756, 11.30993247),
            LineSegment(Point(54.90290337, 0.98058067), c_up)]
        self.assertAlmostEqual(geometry.elements(), expected_elements)

        lane = Street.from_control_points([a, b, c_down]).lane_at(0)
        geometry = lane.path_for(LinesAndArcsGeometry)

        expected_elements = [
            LineSegment(a, Point(45.0, 0.0)),
            Arc(Point(45.0, 0.0), 0.0, 50.49509756, -11.30993247),
            LineSegment(Point(54.90290337, -0.98058067), c_down)]
        self.assertAlmostEqual(geometry.elements(), expected_elements)
コード例 #23
0
    def test_get_roads_Y_type(self):
        """
        (0,0)--(1,0)--(6,1)
                  |---(6,-0.8)
        Note that (6,1) is discarded only because (6,-0.8) is a better
        candidate, but both are eligible
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(6, 1))
        n4 = GraphNode(Point(6, -0.8))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n2, n4)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4]).run()
        intersection = RoadIntersectionNode.on(1, 0)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), intersection, RoadSimpleNode.on(6, -0.8)]),
            Street.from_nodes([RoadSimpleNode.on(6, 1), intersection])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
コード例 #24
0
    def test_sample_city(self):
        city = City()

        city.add_road(
            Street.from_control_points(
                [Point(-100, 0), Point(0, 0),
                 Point(100, 0)]))
        city.add_road(
            Street.from_control_points(
                [Point(0, 100), Point(0, 0),
                 Point(0, -100)]))
        city.add_intersection_at(Point(0, 0))

        city.add_road(
            Street.from_control_points([
                Point(-10, 200),
                Point(0, 200),
                Point(10, 220),
                Point(20, 270)
            ]))

        stats = CityStatistics(city)
        values = stats.run()
        self.assertEquals(values['roads_count'], 3)
        self.assertEquals(values['lanes_count'], 3)
        self.assertEquals(values['buildings_count'], 0)
        self.assertEquals(values['blocks_count'], 0)
        self.assertEquals(values['polyline_waypoints_count'], 12)
        self.assertEquals(values['polyline_intersections_count'], 4)
        self.assertEquals(values['average_polyline_intersections'], 4.0 / 3.0)
        self.assertEquals(values['average_polyline_waypoints'], 12.0 / 3.0)
        self.assertEquals(values['lines_and_arcs_waypoints_count'], 14)
        self.assertEquals(values['lines_and_arcs_intersections_count'], 4)
        self.assertEquals(values['average_lines_and_arcs_intersections'],
                          4.0 / 3.0)
        self.assertEquals(values['average_lines_and_arcs_waypoints'],
                          14.0 / 3.0)
コード例 #25
0
    def broken_intersection_on_two_lanes_city(self):
        """
                      (10,50)
                         |
                        |    __--- (50,20)
        (-50,0) ------- + ---
                        |
                        |
                      (0,-50)
        """
        city = City("Broken intersection - Two lanes")

        s1 = Street.from_control_points([Point(-50, 0), Point(0, 0), Point(50, 20)])
        s1.name = "s1"

        s2 = Street.from_control_points([Point(0, -50), Point(0, 0), Point(10, 50)])
        s2.name = "s2"

        city.add_intersection_at(Point(0, 0))

        city.add_road(s1)
        city.add_road(s2)

        return city
コード例 #26
0
    def collinear_streets_city(self):
        """
         --->---+--->---
        """
        city = City("Collinear streets")

        s1 = Street.from_control_points([
            Point(0, 0),
            Point(50, 0)
        ])
        s1.name = "s1"

        s2 = Street.from_control_points([
            Point(50, 0),
            Point(100, 0)
        ])
        s2.name = "s2"

        city.add_road(s1)
        city.add_road(s2)

        city.add_intersection_at(Point(50, 0))

        return city
コード例 #27
0
    def test_elements_short_S_path(self):
        a = Point(0, 0)
        b = Point(50, 0)
        c = Point(50, 10)
        d = Point(100, 10)

        lane = Street.from_control_points([a, b, c, d]).lane_at(0)
        geometry = lane.path_for(LinesAndArcsGeometry)

        expected_elements = [
            LineSegment(a, Point(45, 0)),
            Arc(Point(45, 0), 0, 5, 90),
            Arc(Point(50, 5), 90, 5, -90),
            LineSegment(Point(55, 10), d)]
        self.assertAlmostEqual(geometry.elements(), expected_elements)
コード例 #28
0
    def test_get_roads_Y_street_best_neighbour_street(self):
        """
        (0,0)--(1,0)--(6,1)(trunk)
                  |---(6,-0.8)
        Expected: main street:[(0,0),(1,0),(6,-0.8)]
                  access street:[(1,0), (6,1)]
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(6, 1))
        n3.is_minor_road = False  # make trunk
        n4 = GraphNode(Point(6, -0.8))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n2, n4)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4]).run()
        intersection = RoadIntersectionNode.on(1, 0)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), intersection, RoadSimpleNode.on(6, -0.8)]),
            Street.from_nodes([intersection, RoadSimpleNode.on(6, 1)])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
コード例 #29
0
    def test_get_roads_one_aligned_segment(self):
        """
        (0,0)--(1,0)
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))

        self._connect(n1, n2)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2]).run()

        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), RoadSimpleNode.on(1, 0)])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
コード例 #30
0
    def test_get_roads_one_not_aligned_segment(self):
        """
        (0,0)--(1,1)
        Event though the angles don't match (45deg), the road is built as there
        is only a single possible path.
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 1))

        self._connect(n1, n2)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2]).run()

        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), RoadSimpleNode.on(1, 1)])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)