Beispiel #1
0
def test_osm_xml():

    # test osm xml output
    ox.settings.all_oneway = True
    G = ox.graph_from_place('Piedmont, California, USA')
    ox.save_as_osm(G, merge_edges=False)

    # test osm xml output merge edges
    ox.save_as_osm(G, merge_edges=True, edge_tag_aggs=[('length', 'sum')])

    # test osm xml output from gdfs
    nodes, edges = ox.graph_to_gdfs(G)
    ox.save_as_osm([nodes, edges])

    # test ordered nodes from way
    df = pd.DataFrame({
        'u': [54, 2, 5, 3, 10, 19, 20],
        'v': [76, 3, 8, 10, 5, 20, 15]
    })
    ordered_nodes = ox.get_unique_nodes_ordered_from_way(df)
    assert ordered_nodes == [2, 3, 10, 5, 8]
Beispiel #2
0
def test_osm_xml_output_from_gdfs():
    ox.settings.all_oneway = True
    G = ox.graph_from_place('Piedmont, California, USA')
    nodes, edges = ox.graph_to_gdfs(G)
    ox.save_as_osm([nodes, edges])
Beispiel #3
0
def test_osm_xml_output():
    ox.settings.all_oneway = True
    G = ox.graph_from_place('Piedmont, California, USA')
    ox.save_as_osm(G)
    if save_as == 'shp':
        out_path = os.path.join(data_dir, out_fname)
        # turn the edges back to a graph to save as shapefile
        logger.info('Saving graph as shapefile. This might take a while...')
        nodes.gdf_name = 'nodes'
        # ox.save_gdf_shapefile(nodes, 'nodes', out_path)
        edges.gdf_name = 'edges'
        ox.save_gdf_shapefile(edges, 'edges', out_path)

    elif save_as in ['osm', 'pbf']:
        logger.info('Saving graph as OSM XML. This might take a while...')
        ox.save_as_osm([nodes, edges],
                       filename=out_fname + '.osm',
                       folder=data_dir,
                       node_tags=ox.settings.osm_xml_node_tags,
                       node_attrs=ox.settings.osm_xml_node_attrs,
                       edge_tags=ox.settings.osm_xml_way_tags,
                       edge_attrs=ox.settings.osm_xml_way_attrs,
                       merge_edges=False)

        if save_as == 'pbf':
            logger.info('Converting OSM XML to .pbf')
            os.system("osmconvert {0}.osm -o={0}.osm.pbf".format(
                os.path.join(data_dir, out_fname)))
            logger.info('File now available at {0}'.format(
                os.path.join(data_dir, out_fname + '.osm.pbf')))
    else:
        raise ValueError(
            "{0} is not a valid output file type. See --help for more "
            "details.".format(save_as))
Beispiel #5
0
def test_osm_xml_output_merge_edges():
    ox.settings.all_oneway = True
    G = ox.graph_from_place('Piedmont, California, USA')
    ox.save_as_osm(G, merge_edges=True, edge_tag_aggs=[('length', 'sum')])