Exemple #1
0
def route_analysis_df(route_num, shapefile, rasterfile):
    """
       input the number of route, then output a GeoDataFrame with gradient and geometry
    information of that route, and elevation_gradient for each line segment. 
    Also will save the route as shapefile named 'route_shp'.
    
    Parameters
    ----------
    route_num: desired route number (integer)
    shapefile: route geospatial data (.shp file)
    rasterfile: elevation data file (.tif)
    
    Returns
    -------
    gdf_route: geodataframe with columns ['gradient', 'geometry']
    
    """
    route_shp = base.read_shape(shapefile, route_num)
    
    linestring_route_df = base.extract_point_df(route_shp)
    
    elevation, elevation_gradient, route_cum_distance, distance = base.gradient(route_shp, rasterfile)

    gdf_route = base.make_multi_lines( linestring_route_df, elevation_gradient) 
    
    return gdf_route
Exemple #2
0
def route_analysis_profile(route_num, shapefile, rasterfile):
    """
       input the number of route, then output elevation and road grade profiles.
    Also will save the route as shapefile named 'route_shp'.
    
    Parameters
    ----------
    route_num: desired route number (integer)
    shapefile: route geospatial data (.shp file)
    rasterfile: elevation data file (.tif)
    
    Returns
    -------
    route_plot: elevation and grade profiles for desired route
    """
    route_shp = base.read_shape(shapefile, route_num)
    
    linestring_route_df = base.extract_point_df(route_shp)
    
    elevation, elevation_gradient, route_cum_distance, distance = base.gradient(route_shp, rasterfile)

    gdf_route = base.make_multi_lines( linestring_route_df, elevation_gradient) 
    
    route_plot = base.profile_plot(elevation, elevation_gradient, route_cum_distance, route_num)
    
    return route_plot
Exemple #3
0
def route_analysis_map(route_num, shapefile, rasterfile):
    """
       input the number of route, then output an interactive map showing the route and road grade. 
    Also will save the route as shapefile named 'route_shp'.
    
    Parameters
    ----------
    route_num: desired route number (integer)
    shapefile: route geospatial data (.shp file)
    rasterfile: elevation data file (.tif)
    
    Returns
    -------
    map_display: interactive map for desired route
    """
    route_shp = base.read_shape(shapefile, route_num)
    
    linestring_route_df = base.extract_point_df(route_shp)
    
    elevation, elevation_gradient, route_cum_distance, distance = base.gradient(route_shp, rasterfile)

    gdf_route = base.make_multi_lines( linestring_route_df, elevation_gradient) 
    
    map_display = base.route_map(gdf_route)
    
    return map_display
Exemple #4
0
def route_analysis_all(route_num, shapefile, rasterfile):
    """
       input the number of route, then output an interactive map of the route, elevation and road grade profiles, and metrics calculated for the route. 
    Also will save the route as shapefile named 'route_shp'.
    
    Parameters
    ----------
    route_num: Desired route number (integer)
    shapefile: route geospatial data (.shp file)
    rasterfile: elevation data file (.tif)
    
    Returns
    -------
    map_display: interactive map for desired route
    route_plot: elevation and grade profiles for desired route
    display_metrics: results of metrics calculations
    """
    route_shp = base.read_shape(shapefile, route_num)
    
    linestring_route_df = base.extract_point_df(route_shp)
    
    elevation, elevation_gradient, route_cum_distance, distance = base.gradient(route_shp, rasterfile)

    gdf_route = base.make_multi_lines( linestring_route_df, elevation_gradient) 
    
    map_display = base.route_map(gdf_route)
    
    route_plot = base.profile_plot(elevation, elevation_gradient, route_cum_distance, route_num)
    
    display_metrics, _ = base.route_metrics(elevation, elevation_gradient, route_cum_distance, distance, route_num)
    
    return map_display, route_plot, display_metrics
Exemple #5
0
def test_extract_point_df():
    """Test if the shape of dataframe is correct."""
    df45 = base.read_shape(shapefile, route_num)
    shape = base.extract_point_df(df45).shape
    assert shape == (208,
                     1), " Shape of df(route 45) coordinates should be (208,1)"
    return
Exemple #6
0
def test_read_shape():
    """
        Test if shapefile is for route number 45
        
        Parameters
        ----------
        shapefile: The path of a shapefile(.shp)
        
    """
    assert shapefile.endswith('.shp'), 'Input should be shapefile.'
    assert base.read_shape(
        shapefile, 45)['ROUTE_NUM'].values[0] == 45, 'ROUTE_NUM is wrong!'
    return
def routes_analysis_ranking(route_list, shapefile, rasterfile):
    """
    Computes the four chosen metrics values for each bus routes in route_list and display them on a bar plot for
    ease of comparison

    Parameters
    ----------
    route_list: A list of bus routes to be compared (Integers)
    shapefile: route geospatial data (.shp file)
    rasterfile: elevation data file (.tif)

    Returns
    -------
    bar plot: showing results comparison between bus routes according to the four metrics chosen
    """
    num_route = len(route_list)
    metrics_1 = [0] * num_route
    metrics_2 = [0] * num_route
    metrics_3 = [0] * num_route
    metrics_4 = [0] * num_route
    for idx, route_num in enumerate(route_list):
        route_shp = base.read_shape(shapefile, route_num)

        elevation, elevation_gradient, route_cum_distance, distance = base.gradient(
            route_shp, rasterfile)

        _, metrics = base.route_metrics(elevation, elevation_gradient,
                                        route_cum_distance, distance,
                                        route_num)

        metrics_1[idx], metrics_2[idx], metrics_3[idx], metrics_4[
            idx] = metrics

    data = pd.DataFrame({
        'Bus Num': route_list,
        'M1': metrics_1,
        'M2': metrics_2,
        'M3': metrics_3,
        'M4': metrics_4
    })
    ax = data.plot.bar('Bus Num', figsize=[14, 5], fontsize=20)
    ax.set_ylabel('Metrics', size=20)
    ax.set_xlabel('Bus Number', size=20)

    return ax
Exemple #8
0
def route_analysis_metrics(route_num, shapefile, rasterfile):
    """
       input the number of route, then output the metrics calculated for that route. 
    Also will save the route as shapefile named 'route_shp'.
    
    Parameters
    ----------
    route_num: Desired route number (integer)
    shapefile: route geospatial data (.shp file)
    rasterfile: elevation data file (.tif)
    
    Returns
    -------
    display_metrics: results of metrics calculations
    """
    route_shp = base.read_shape(shapefile, route_num)
    
    linestring_route_df = base.extract_point_df(route_shp)
    
    elevation, elevation_gradient, route_cum_distance, distance = base.gradient(route_shp, rasterfile)
    
    display_metrics, _ = base.route_metrics(elevation, elevation_gradient, route_cum_distance, distance, route_num)
    
    return display_metrics