コード例 #1
0
    def test_two_edge_path(self):
        first_start = data_factory.right_angle_start
        first_middle = data_factory.right_angle_middle
        first_end = data_factory.right_angle_end
        first_right_angled_road = data_factory.create_part(
            first_start, first_middle, first_end)

        second_start = first_end
        second_middle = Point('%.1f' % (first_end.latitude + 0.1),
                              first_end.longitude)
        second_end = Point('%.1f' % (first_end.latitude + 0.1),
                           '%.1f' % (first_end.longitude + 0.1))
        second_right_angled_road = data_factory.create_part(
            second_start, second_middle, second_end)

        shapefile = data_factory.create_shapefile([first_right_angled_road] +
                                                  [second_right_angled_road])

        networkx = convert._to_networkx_graph(shapefile)
        G = convert.load_graph_from_shapefile_records(networkx)

        actual_distance = distance.using_route(G, first_start, second_end)

        self.assertTrue(
            abs(actual_distance -
                (data_factory.right_angle_distance * 2)) < 1 * ureg.metre)
コード例 #2
0
    def create_two_edge_long_road(self, start, end):
        first_start = start
        first_end = Point('%.1f' % (first_start.latitude + 45),
                          '%.1f' % (first_start.longitude + 45))
        first_road = data_factory.create_part(first_start, first_end)

        second_start = first_end
        second_end = end
        second_road = data_factory.create_part(second_start, second_end)

        return [first_road, second_road]
コード例 #3
0
    def test_right_angle(self):
        road = data_factory.create_part(self.start, self.middle, self.end)
        shapefile = data_factory.create_shapefile([road])
        networkx = list(convert._to_networkx_graph(shapefile))

        self.assertEqual(len(networkx), 1)
        self.assertEqual(networkx[0][START_KEY], self.start)
        self.assertEqual(networkx[0][END_KEY], self.end)
        self.assertTrue(
            abs(networkx[0][DISTANCE_KEY] -
                data_factory.right_angle_distance) < 1 * ureg.millimetre)
コード例 #4
0
    def create_three_edge_short_road(self, start, end):
        first_start = start
        first_end = Point(
            '%.3f' %
            (((end.latitude - start.latitude) * 0.2) + start.latitude),
            '%.3f' %
            (((end.longitude - start.longitude) * 0.2) + start.longitude))
        first_road = data_factory.create_part(first_start, first_end)

        second_start = first_end
        second_end = Point(
            '%.3f' %
            (((end.latitude - start.latitude) * 0.8) + start.latitude),
            '%.3f' %
            (((end.longitude - start.longitude) * 0.8) + start.longitude))
        second_road = data_factory.create_part(second_start, second_end)

        third_start = second_end
        third_end = end
        third_road = data_factory.create_part(third_start, third_end)

        return [first_road, second_road, third_road]
コード例 #5
0
    def test_simple_triangle(self):
        right_angled_road = data_factory.create_part(
            data_factory.right_angle_start, data_factory.right_angle_middle,
            data_factory.right_angle_end)
        shapefile = data_factory.create_shapefile([right_angled_road])

        networkx = convert._to_networkx_graph(shapefile)
        G = convert.load_graph_from_shapefile_records(networkx)
        actual_distance = distance.using_route(G,
                                               data_factory.right_angle_start,
                                               data_factory.right_angle_end)

        self.assertEqual(actual_distance, data_factory.right_angle_distance)
コード例 #6
0
    def test_there_and_back(self):
        right_angled_road = data_factory.create_part(
            data_factory.right_angle_start, data_factory.right_angle_middle,
            data_factory.right_angle_end)
        shapefile = data_factory.create_shapefile([right_angled_road])

        networkx = convert._to_networkx_graph(shapefile)
        G = convert.load_graph_from_shapefile_records(networkx)

        outward_distance = distance.using_route(G,
                                                data_factory.right_angle_start,
                                                data_factory.right_angle_end)
        self.assertEqual(outward_distance, data_factory.right_angle_distance)

        inward_distance = distance.using_route(G, data_factory.right_angle_end,
                                               data_factory.right_angle_start)
        self.assertEqual(inward_distance, data_factory.right_angle_distance)