def get_selection(file_name):
    """
    Get selection from an XML file.  Returns a dictionary with the data from the file 
    or None if unable to read/parse the file.
    :param file_name: string
    :return: selection data dictionary
    """

    selection = get_data_from_file(file_name)
    if selection is None:
        return None

    selection_data = {
        'name':
        file_name,
        'raw_data':
        selection,
        'from_file':
        'yes',
        'paths': [p for p in selection[0]['elements'] if p['type'] == 'way'],
        'nodes':
        get_nodes_dict(selection, nodes_dict={}),
        'relations':
        [p for p in selection[0]['elements'] if p['type'] == 'relation']
    }

    add_missing_highway_tag(selection_data['paths'],
                            get_streets(selection_data))

    return insert_street_names(selection_data)
def crop_selection(selection, x0, y0, nodes_dict=None, radius=150.0):
    """
    Crop the selection to a smaller radius
    :param selection: list of intersection data in the osmnx format
    :param x0: float: center coordinate
    :param y0: float: center coordinate
    :param nodes_dict: dictionary
    :param radius: float in meters: cropping radius
    :return: cropped list of intersection data in the osmnx format
    """
    if nodes_dict is None:
        nodes_dict = get_nodes_dict(selection, nodes_dict={})

    cropped_selection = []

    for s in selection:
        s_cropped = {
            'version': s['version'],
            'osm3s': s['osm3s'],
            'generator': s['generator'],
            'elements': s['elements']
        }
        s_cropped['element'] = remove_elements_beyond_radius(
            s_cropped['elements'], nodes_dict, x0, y0, radius)
        cropped_selection.append(s_cropped)

    return cropped_selection
def get_city(city_name):
    """
    Get city data as a dictionary.
    :param city_name: city name like 'Campbell, California, USA'
    :return: city data dictionary
    """

    city_paths_nodes = get_city_from_osm(city_name)

    if city_paths_nodes is None:
        return None

    city_data = {
        'name':
        city_name,
        'raw_data':
        None,
        'from_file':
        'no',
        'paths':
        [p for p in city_paths_nodes[0]['elements'] if p['type'] == 'way'],
        'nodes':
        get_nodes_dict(city_paths_nodes, nodes_dict={}),
        'relations': [
            p for p in city_paths_nodes[0]['elements']
            if p['type'] == 'relation'
        ]
    }

    add_missing_highway_tag(city_data['paths'], get_streets(city_data))

    return insert_street_names(city_data)
def get_street_structure(city_name):
    """
    Get street structure of a city
    :param city_name: city name like 'Campbell, California, USA'
    :return: a tuple of list of paths and a nodes dictionary
    """
    city_boundaries = ox.gdf_from_place(city_name)
    city_paths_nodes = ox.osm_net_download(
        city_boundaries['geometry'].unary_union, network_type="drive")
    nodes_dict = get_nodes_dict(city_paths_nodes)
    paths = [p for p in city_paths_nodes[0]['elements'] if p['type'] != 'node']
    return paths, nodes_dict