Example #1
0
 def save_graph(self):
     ox.save_graph_osm(
         self.graph,
         filename=f'{OSM_OUTPUT_FILENAME}.osm',
         folder=OSM_OUTPUT_DIR,
         # oneway=False,
     )
     logger.info(
         f'Saved osm xml to {OSM_OUTPUT_DIR}/{OSM_OUTPUT_FILENAME}.osm')
Example #2
0
def test_osm_xml_output():
    G = ox.graph_from_place('Piedmont, California, USA')
    ox.save_graph_osm(G)
Example #3
0
def test_osm_xml_output():
    G = ox.graph_from_place('Piedmont, California, USA')
    ox.save_graph_osm(G)
Example #4
0
    """
    # Find nodes closest to the specified coordinates
    node_start = ox.utils.get_nearest_node(area_graph, startpoint)
    node_stop = ox.utils.get_nearest_node(area_graph, endpoint)
    #Calculate the shortest network distance between the nodes via the edges length
    try:
        distance = round(nx.shortest_path_length(area_graph, node_start, node_stop, weight="length"),0)
    # return NA if no path exists
    except nx.NetworkXNoPath:
        distance = "NA"
    return distance

print("Downloading Dublin maps from OpenStreetMap API...")
# Load map from OpenStreetMap API
G = ox.graph_from_place('Dublin, Ireland', network_type='drive')
ox.save_graph_osm(G, filename='mynetwork.osm')
E = ox.graph_from_file(filename='data\mynetwork.osm', bidirectional = False)

# Settings for Streetnetwork-Download
map_file = 'data\mynetwork.osm'
force_creat = False

#Checks if the Streetnetwork File exists (or creation is overwritten)
if (not os.path.isfile(map_file))or force_creat:
    area_graph = ox.graph_from_place('Dublin, Ireland', network_type='drive')
    ox.save_graph_osm(area_graph, filename=map_file)
else:
    area_graph = ox.graph_from_file(filename = map_file, bidirectional = False)

print("Map download complete")
    'unclassified', 'road'
]

minor_streets = [(u, v, k) for u, v, k, d in G.edges(keys=True, data=True)
                 if d['highway'] not in types]

# remove minor streets and retain only the largest connected component subgraph
G_ter = G
G_ter.remove_edges_from(minor_streets)
G_ter = ox.remove_isolated_nodes(G_ter)
G_ter_connected = ox.get_largest_component(G_ter, strongly=True)

# then simplify the graph now that we have only the edge types we want
G_ter_simp = ox.simplify_graph(G_ter_connected, strict=True)

# create a unique ID for each edge because osmid can
# hold multiple values due to topology simplification
i = 0
for u, v, k, d in G_ter_simp.edges(data=True, keys=True):
    d['uniqueid'] = i
    i += 1

# convert to two-way
H = ox.get_undirected(G_ter_simp)

# save graph as OSM
ox.save_graph_osm(
    H,
    oneway=False,
    filename='bay_area_simplified_tertiary_strongly_2_way_network.osm')