def get_footway_data(x_data, city_data):
    """
    Get footway data if applicable for the intersection and crop within the radius.
    :param x_data: dictionary
    :param city_data: dictionary 
    :return: list of railway paths 
    """
    nodes_dict = city_data['nodes']
    footway_jsons = get_box_data(x_data,
                                 city_data['raw_data'],
                                 network_type='all')

    footway_paths = [
        e for e in footway_jsons[0]['elements'] if e['type'] == 'way'
        and 'highway' in e['tags'] and 'foot' in e['tags']['highway']
    ]

    x_data['footway_paths'] = copy.deepcopy(footway_paths)

    add_nodes_to_dictionary(
        [e for e in footway_jsons[0]['elements'] if e['type'] == 'node'],
        nodes_dict,
        paths=footway_paths)
    paths_with_borders = add_borders_to_paths(footway_paths,
                                              nodes_dict,
                                              width=1.8)
    cropped_paths = remove_elements_beyond_radius(paths_with_borders,
                                                  nodes_dict,
                                                  x_data['center_x'],
                                                  x_data['center_y'],
                                                  x_data['crop_radius'])
    set_direction(cropped_paths, x_data, nodes_dict)
    return sorted(cropped_paths, key=lambda p: p['id'])
def get_street_data(x_data, city_data):
    """
    Get a list of paths related to the intersection and a list of data matching the osmnx format.
    :param x_data: dictionary
    :param city_data: dictionary
    :return: a tuple of lists
    """

    nodes_dict = city_data['nodes']
    intersection_jsons = get_box_data(x_data,
                                      city_data['raw_data'],
                                      infrastructure='way["highway"]',
                                      network_type='drive')
    x_data['raw_data'] = copy.deepcopy(intersection_jsons)
    intersection_paths = [
        e for e in intersection_jsons[0]['elements'] if e['type'] == 'way'
    ]
    add_nodes_to_dictionary(
        [e for e in intersection_jsons[0]['elements'] if e['type'] == 'node'],
        nodes_dict,
        paths=intersection_paths)

    manual_correction(intersection_paths)
    split_x_streets = repeat_street_split(intersection_paths, nodes_dict,
                                          x_data['streets'])
    oneway_paths = split_bidirectional_paths(split_x_streets, nodes_dict)
    set_direction(oneway_paths, x_data, nodes_dict)
    correct_paths(oneway_paths)
    oneway_paths_with_borders = add_borders_to_paths(oneway_paths, nodes_dict)

    cropped_paths = remove_elements_beyond_radius(oneway_paths_with_borders,
                                                  nodes_dict,
                                                  x_data['center_x'],
                                                  x_data['center_y'],
                                                  x_data['crop_radius'])
    cleaned_intersection_paths = sorted(clean_paths(cropped_paths,
                                                    x_data['streets']),
                                        key=lambda p: p['id'])
    node_subset = get_node_subset(intersection_jsons,
                                  cleaned_intersection_paths, nodes_dict)
    intersection_selection = [{
        'version':
        intersection_jsons[0]['version'],
        'osm3s':
        intersection_jsons[0]['osm3s'],
        'generator':
        intersection_jsons[0]['generator'],
        'elements':
        node_subset + cleaned_intersection_paths
    }]

    return cleaned_intersection_paths, intersection_selection, intersection_jsons
def get_public_transit_data(x_data, city_data):
    """
    Get public transit data if applicable for the intersection and crop within the radius.
    :param x_data: dictionary
    :param city_data: dictionary 
    :return: list of railway paths 
    """
    nodes_dict = city_data['nodes']
    public_transit_jsons = get_box_data(x_data,
                                        city_data['raw_data'],
                                        network_type='all',
                                        infrastructure='node["highway"]')

    public_transit_nodes = [
        e for e in public_transit_jsons[0]['elements'] if e['type'] == 'node'
        and 'tags' in e and 'stop' in ' '.join(e['tags'].values())
    ]

    add_nodes_to_dictionary(public_transit_nodes, nodes_dict, paths=None)

    return public_transit_nodes
def get_railway_data(x_data, city_data):
    """
    Get railway data if applicable for the intersection and crop within the radius.
    :param x_data: dictionary
    :param city_data: dictionary 
    :return: list of railway paths 
    """
    nodes_dict = city_data['nodes']
    railway_jsons = get_box_data(x_data,
                                 city_data['raw_data'],
                                 network_type='all',
                                 infrastructure='way["railway"]')

    railway_paths = [
        e for e in railway_jsons[0]['elements'] if e['type'] == 'way'
    ]
    x_data['railway_paths'] = copy.deepcopy(railway_paths)
    referenced_nodes = {}
    referenced_nodes = get_node_dict_subset_from_list_of_lanes(
        x_data['merged_lanes'], nodes_dict, referenced_nodes)
    split_railway_paths = split_railways(remove_subways(railway_paths),
                                         referenced_nodes)
    add_nodes_to_dictionary(
        [e for e in railway_jsons[0]['elements'] if e['type'] == 'node'],
        nodes_dict,
        paths=railway_paths)
    paths_with_borders = add_borders_to_paths(split_railway_paths,
                                              nodes_dict,
                                              width=2.0)
    cropped_paths = remove_elements_beyond_radius(paths_with_borders,
                                                  nodes_dict,
                                                  x_data['center_x'],
                                                  x_data['center_y'],
                                                  x_data['crop_radius'])
    set_direction(cropped_paths, x_data, nodes_dict)
    return sorted(cropped_paths, key=lambda p: p['id'])