def read_osm(osm_file_path, osm_read_config, num_processes: int = 1, epsg=None): """ Reads OSM data into a graph of the Network object :param osm_file_path: path to .osm or .osm.pbf file :param osm_read_config: config file (see configs folder in genet for examples) which informs for example which highway types to read (in case of road network) and what modes to assign to them :param num_processes: number of processes to split parallelisable operations across :param epsg: projection for the output Network, e.g. 'epsg:27700'. If not provided, defaults to epsg:4326 :return: genet.Network object """ if epsg is None: epsg = 'epsg:4326' config = osm_reader.Config(osm_read_config) n = core.Network(epsg) nodes, edges = osm_reader.generate_osm_graph_edges_from_file( osm_file_path, config, num_processes) nodes_and_attributes = parallel.multiprocess_wrap( data=nodes, split=parallel.split_dict, apply=osm_reader.generate_graph_nodes, combine=parallel.combine_dict, epsg=epsg, processes=num_processes ) reindexing_dict, nodes_and_attributes = n.add_nodes(nodes_and_attributes, ignore_change_log=True) edges_attributes = parallel.multiprocess_wrap( data=edges, split=parallel.split_list, apply=osm_reader.generate_graph_edges, combine=parallel.combine_list, reindexing_dict=reindexing_dict, nodes_and_attributes=nodes_and_attributes, config_path=osm_read_config, processes=num_processes ) n.add_edges(edges_attributes, ignore_change_log=True) logging.info('Deleting isolated nodes which have no edges.') n.remove_nodes(list(nx.isolates(n.graph))) return n
def slim_default_config(): return osm_reader.Config( os.path.join(os.path.dirname(__file__), "..", "configs", "slim_config.yml"))
def full_fat_default_config(): return osm_reader.Config( os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "configs", "default_config.yml")))