예제 #1
0
파일: monav.py 프로젝트: fferner/modrana
def get_route(data_directory,
              waypoints,
              lookup_radius=10000,
              lookup_edge_names=True,
              connection=None):
    """Get the shortest route between a list of waypoints using MoNav.

    * connection should be a TcpConnection object.

    * data_directory should be the path to the directory called routing_
      created by the MoNav preprocessor.

    * Return type RoutingResult:
        seconds
        nodes
        edges
        edge_names
        edge_types

    * First start the monav-server.

    """
    if not connection:
        connection = TcpConnection()

    # Generate and write the command type.
    connection.write(CommandType(value=CommandType.ROUTING_COMMAND))

    # Generate the command.
    command = RoutingCommand()
    command.data_directory = data_directory
    command.lookup_radius = lookup_radius
    command.lookup_edge_names = lookup_edge_names

    wayP = []

    for point in waypoints:
        lat, lon = point
        w = Waypoint()
        w.latitude = lat
        w.longitude = lon
        wayP.append(w)

    command.waypoints.extend(wayP)
    #    if hasattr(waypoints[0], 'latitude'):
    #        command.waypoints.extend(waypoints)
    #    else:
    #        for latlon in waypoints:
    #            assert len(latlon) == 2
    #            waypoint = command.waypoints.add(latitude=latlon[0], longitude=latlon[1])

    # Write the command.
    log.debug("COMMAND")
    log.debug(command)

    connection.write(command)

    # Read result.
    result = RoutingResult()
    connection.read(result)

    # Close the connection (just in case)
    connection.close()

    return result
예제 #2
0
파일: monav.py 프로젝트: Karry/monav
def get_route(data_directory, waypoints, lookup_radius=10000, lookup_edge_names=True, connection=None):
    """Get the shortest route between a list of waypoints using MoNav.

    * connection should be a TcpConnection object.

    * data_directory should be the path to the directory called routing_
      created by the MoNav preprocessor.

    * Return type RoutingResult:
        seconds
        nodes
        edges
        edge_names
        edge_types

    * First start the monav-server.

    """
    if not connection:
        connection = TcpConnection()

    # Generate and write the command type.
    connection.write(CommandType(value=CommandType.ROUTING_COMMAND))

    # Generate the command.
    command = RoutingCommand()
    command.data_directory = data_directory
    command.lookup_radius = lookup_radius
    command.lookup_edge_names = lookup_edge_names

    if hasattr(waypoints[0], 'latitude'):
        command.waypoints.extend(waypoints)
    else:
        for latlon in waypoints:
            assert len(latlon) == 2
            waypoint = command.waypoints.add(latitude=latlon[0], longitude=latlon[1])

    # Write the command.
    connection.write(command)

    # Read result.
    result = RoutingResult()
    connection.read(result)

    # Close the connection (just in case)
    connection.close()

    if result.type == RoutingResult.SUCCESS:
        return result
    elif result.type == RoutingResult.LOAD_FAILED:
        raise Exception(str(result.type) + ": failed to load data directory")
    elif result.type == RoutingResult.LOOKUP_FAILED:
        raise Exception(str(result.type) + ": failed to lookup nearest edge")
    elif result.type == RoutingResult.ROUTE_FAILED:
        raise Exception(str(result.type) + ": failed to compute route")
    elif result.type == RoutingResult.NAME_LOOKUP_FAILED:
        raise Exception(str(result.type) + ": name lookup failed")
    elif result.type == RoutingResult.TYPE_LOOKUP_FAILED:
        raise Exception(str(result.type) + ": type lookup failed")
    else:
        raise Exception(str(result.type) + ": return value not recognized")
예제 #3
0
파일: monav.py 프로젝트: fferner/modrana
def get_route(data_directory, waypoints, lookup_radius=10000, lookup_edge_names=True, connection=None):
    """Get the shortest route between a list of waypoints using MoNav.

    * connection should be a TcpConnection object.

    * data_directory should be the path to the directory called routing_
      created by the MoNav preprocessor.

    * Return type RoutingResult:
        seconds
        nodes
        edges
        edge_names
        edge_types

    * First start the monav-server.

    """
    if not connection:
        connection = TcpConnection()

    # Generate and write the command type.
    connection.write(CommandType(value=CommandType.ROUTING_COMMAND))

    # Generate the command.
    command = RoutingCommand()
    command.data_directory = data_directory
    command.lookup_radius = lookup_radius
    command.lookup_edge_names = lookup_edge_names

    wayP = []

    for point in waypoints:
        lat, lon = point
        w = Waypoint()
        w.latitude = lat
        w.longitude = lon
        wayP.append(w)

    command.waypoints.extend(wayP)
    #    if hasattr(waypoints[0], 'latitude'):
    #        command.waypoints.extend(waypoints)
    #    else:
    #        for latlon in waypoints:
    #            assert len(latlon) == 2
    #            waypoint = command.waypoints.add(latitude=latlon[0], longitude=latlon[1])

    # Write the command.
    log.debug("COMMAND")
    log.debug(command)

    connection.write(command)

    # Read result.
    result = RoutingResult()
    connection.read(result)

    # Close the connection (just in case)
    connection.close()

    return result
예제 #4
0
def get_route(data_directory,
              waypoints,
              lookup_radius=10000,
              lookup_edge_names=True,
              connection=None):
    """Get the shortest route between a list of waypoints using MoNav.

    * connection should be a TcpConnection object.

    * data_directory should be the path to the directory called routing_
      created by the MoNav preprocessor.

    * Return type RoutingResult:
        seconds
        nodes
        edges
        edge_names
        edge_types

    * First start the monav-server.

    """
    if not connection:
        connection = TcpConnection()

    # Generate and write the command type.
    connection.write(CommandType(value=CommandType.ROUTING_COMMAND))

    # Generate the command.
    command = RoutingCommand()
    command.data_directory = data_directory
    command.lookup_radius = lookup_radius
    command.lookup_edge_names = lookup_edge_names

    if hasattr(waypoints[0], 'latitude'):
        command.waypoints.extend(waypoints)
    else:
        for latlon in waypoints:
            assert len(latlon) == 2
            waypoint = command.waypoints.add(latitude=latlon[0],
                                             longitude=latlon[1])

    # Write the command.
    connection.write(command)

    # Read result.
    result = RoutingResult()
    connection.read(result)

    # Close the connection (just in case)
    connection.close()

    if result.type == RoutingResult.SUCCESS:
        return result
    elif result.type == RoutingResult.LOAD_FAILED:
        raise Exception(str(result.type) + ": failed to load data directory")
    elif result.type == RoutingResult.LOOKUP_FAILED:
        raise Exception(str(result.type) + ": failed to lookup nearest edge")
    elif result.type == RoutingResult.ROUTE_FAILED:
        raise Exception(str(result.type) + ": failed to compute route")
    elif result.type == RoutingResult.NAME_LOOKUP_FAILED:
        raise Exception(str(result.type) + ": name lookup failed")
    elif result.type == RoutingResult.TYPE_LOOKUP_FAILED:
        raise Exception(str(result.type) + ": type lookup failed")
    else:
        raise Exception(str(result.type) + ": return value not recognized")