def test_new_route(self): line = LineString((0, 0), (0, 50), (50, 50), (50, 0), srid=32616) line_4326 = LineString((0, 0), (0, 50), (50, 50), (50, 0), srid=4326) route = TestRoutes(name='Route No {}'.format(random.randint(1, 100000)), start=self.start_cell_id, end=self.end_cell_id, distance=0, geom=line, geom_4326=line_4326) route.save() self.assertEqual(0, TestRoutes.objects.get(start=self.start_cell_id).distance)
def create_route(self, start_pt, target_pt): """ Based on points passed through a HTTP request a route is calculated, geometry generated on the basis of it and persisted to the database. :param start_pt: the start point specified :param target_pt: the end point specified :return: the id of the generated and persisted route geometry back to the page which requested it """ start_end = grid_utils.GridUtilities.start_end_points_to_cells(start_pt, target_pt) start_node = start_end[0] end_node = start_end[1] reverse_path = self.path_finder.find_path(start_node, end_node, self.gra.graph_dict) path = self.path_finder.rebuild_path(reverse_path[0], start_node, end_node) route_geoms = _generate_route_geom(path) start_pt_record = GridUtilities.find_cell_centre_projected(start_node, self.qs) end_pt_record = GridUtilities.find_cell_centre_projected(end_node, self.qs) route = TestRoutes(name='Route No {}'.format(random.randint(1, 100000)), distance=round(route_geoms[0].length/1852, 2), geom=route_geoms[0], geom_4326=route_geoms[1], start_geom=start_pt_record, end_geom=end_pt_record) route.save() return route.gid
def bfs_route(start, target): """ Included for completeness but not available through the GUI :param start: :param target: :return: """ bfs_finder = BFSPathFinder() g = pickle.load(open('outfile.txt', 'rb')) gra = graph.Graph(g) print("Graph generated...") BFSPathFinder.find_path_bfs(gra.graph_dict, start) route_cell_gids = BFSPathFinder.find_path_bfs(start, target, bfs_finder.parents[::-1]) print(route_cell_gids) waypoints = [] for item in route_cell_gids: cell = PathGrid.objects.get(pk=item) centre_point = cell.geom.centroid waypoints.append(centre_point) route_line = LineString(waypoints) route = TestRoutes(name='Test route No' + str(random.random), start=start, end=target, distance=route_line.length, geom=route_line) route.save() return route.gid