コード例 #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 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
コード例 #5
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)
コード例 #6
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)
コード例 #7
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
コード例 #8
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)
コード例 #9
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)
コード例 #10
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
コード例 #11
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
コード例 #12
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)
コード例 #13
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
コード例 #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 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)
コード例 #16
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)
コード例 #17
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)
コード例 #18
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
コード例 #19
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
コード例 #20
0
    def S_road_city(self):
        """
              (50,12) *------- (100, 12)
                      |
                      |
            (0, 0) ---* (50,0)
        """
        city = City("S road")

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

        city.add_road(s1)

        return city
コード例 #21
0
    def test_elements_heading_S_path(self):
        a = Point(0, 0)
        b = Point(50, 0)
        c = Point(50, 20)
        d = Point(100, 20)

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

        self.assertAlmostEqual(elements[0].start_heading(), 0)
        self.assertAlmostEqual(elements[0].end_heading(), 0)
        self.assertAlmostEqual(elements[1].start_heading(), 0)
        self.assertAlmostEqual(elements[1].end_heading(), 90)
        self.assertAlmostEqual(elements[2].start_heading(), 90)
        self.assertAlmostEqual(elements[2].end_heading(), 90)
        self.assertAlmostEqual(elements[3].start_heading(), 90)
        self.assertAlmostEqual(elements[3].end_heading(), 0)
        self.assertAlmostEqual(elements[4].start_heading(), 0)
        self.assertAlmostEqual(elements[4].end_heading(), 0)
コード例 #22
0
 def test_line_interpolation_points_single_segment_path(self):
     a, b = self._road_points()[0:2]
     lane = Street.from_control_points([a, b]).lane_at(0)
     geometry = lane.path_for(PolylineGeometry)
     self.assertEquals(geometry.line_interpolation_points(), [a, b])
コード例 #23
0
 def test_elements_single_segment_path(self):
     a, b = self._road_points()[0:2]
     lane = Street.from_control_points([a, b]).lane_at(0)
     geometry = lane.path_for(PolylineGeometry)
     expected_elements = [LineSegment(a, b)]
     self.assertEquals(geometry.elements(), expected_elements)