Funciones de direccionamiento

La biblioteca espacio-temporal incluye funciones de direccionamiento que muestra los límites que generan una vía de acceso entre un nodo y otro.

Para mostrarle cómo utilizar las funciones de direccionamiento de la biblioteca espacio-temporal, los ejemplos de código de este tema utilizan el mapa OSM de la ciudad de Atlanta descargado desde https://www.openstreetmap.org.

Para calcular una ruta:

  1. Cree un direccionador y lea el mapa de OSM:

    >>> router = stc.router()
    >>> router.read_map('atlanta.osm')
    Creating Road Network...
    Road Network Created...
    Creating Network Searcher...
    Network Searcher Created...
    
  2. Defina los puntos inicial y final:

    >>> start = stc.point(33.763261, -84.394897)
    >>> end = stc.point(33.753900, -84.385121)
    
  3. Localice la mejor ruta con el mínimo coste en cuanto a tiempo (la ruta más rápida según el tiempo):

    >>> best_time_route = router.compute_route(start, end, method='time')
    # Check time cost, in the unit of hours
    >>> best_time_route.cost
    0,044188548756240675
    # Check route path (only showing the first three points), which is a list of points in 3-tuple (osm_point_id, lat, lon)
    >>> best_time_route.path[:3]
    [(2036943312, 33.7631862, -84.3939405),
    (3523447568, 33.7632666, -84.3939315),
    (2036943524, 33.7633273, -84.3939155)]
    
  4. Localice la mejor ruta con el mínimo coste en cuanto a distancia (la ruta más rápida en cuanto a distancia):

    >>> best_distance_route = router.compute_route(start, end, method='distance')
    # Check distance cost, in the unit of meters
    >>> best_distance_route.cost
    2042,4082601271236
    # Check route path (only showing the first three points), which is a list of points in 3-tuple (osm_point_id, lat, lon)
    >>> best_distance_route.path[:3]
    [(2036943312, 33.7631862, -84.3939405),
    (3523447568, 33.7632666, -84.3939315),
    (2036943524, 33.7633273, -84.3939155)]