接收始发地和目的地之间的建筑物地址

问题描述 投票:-1回答:2

我正在使用OSMNx并尝试检索起点和终点之间的地址,如下图所示。

  • 是否可以提取两个点或节点之间的地址?

enter image description here

import osmnx as ox
import networkx as nx
import matplotlib.pyplot as plt

address='45 Stodart St, Colac VIC 3250'
G = ox.graph_from_address(address, distance=500, network_type="drive")
fig1, ax1 = ox.plot_graph(G,node_size=0, edge_linewidth=0.5, dpi=250)
  • 是否可以提取两个点或节点之间的地址?
python networkx openstreetmap osmnx
2个回答
1
投票

是否可以提取两个点或节点之间的地址?

是:

import osmnx as ox
ox.config(use_cache=True, log_console=True)

address = '20 W 34th St, Manhattan, NY, USA'
G = ox.graph_from_address(address, dist=500, network_type='drive')

# osmids of nodes at either end of block
# or you could do this programmatically with ox.geocode and ox.get_nearest_node
osmids = [42437644, 42430304]

# bounding box around those nodes, buffered as needed
polygon = ox.graph_to_gdfs(G, edges=False).loc[osmids, 'geometry'].unary_union.envelope
polygon_proj, crs = ox.projection.project_geometry(polygon)
polygon_buff, crs = ox.projection.project_geometry(polygon_proj.buffer(10), crs=crs, to_latlong=True)

# get building footprints and show their addresses
fp = ox.footprints_from_polygon(polygon)
cols = [c for c in fp.columns if 'addr' in c]
fp[cols]

所以是的,这是可能的。但是由于您的特定期望位置是不可能的,因为OpenStreetMap在那里不包含建筑物或地址信息。您发布的屏幕截图来自Google Maps而非OpenStreetMap。


0
投票

检索目标区域的所有街道。

import networkx as nx
import osmnx as ox
import geopandas as gpd
import pandas as pd
import csv
import pprint

ox.config(log_console=True, use_cache=True)

G = ox.graph_from_place('Colac, Victoria, Australia', network_type='drive')
G = ox.project_graph(G)
ints = ox.clean_intersections(G)

gdf = gpd.GeoDataFrame(ints, columns=['geometry'], crs=G.graph['crs'])
X = gdf['geometry'].map(lambda pt: pt.coords[0][0])
Y = gdf['geometry'].map(lambda pt: pt.coords[0][1])

nodes = ox.get_nearest_nodes(G, X, Y, method='kdtree')
connections = {}

for n in nodes:
    connections[n] = set([])
    for nbr in nx.neighbors(G, n):
        for d in G.get_edge_data(n, nbr).values():
            if 'name' in d:
                if type(d['name']) == str:
                    connections[n].add(d['name'])
                elif type(d['name']) == list:
                    for name in d['name']:
                        connections[n].add(name)
                else:
                    connections[n].add(None)
            else:
                connections[n].add(None)
   #%%             
pprint.pprint(connections)
© www.soinside.com 2019 - 2024. All rights reserved.