My problem is: I have the geographical coordinates of a place, but when I use ox.get_nearest_node()
, the node I get is way too far from the coordinates and I don't know why:
import networkx as nx
import matplotlib.pyplot as plt
import osmnx as ox
import geopandas as gpd
ox.config(log_console=True, use_cache=True)
place = 'Portugal, Lisbon'
G = ox.graph_from_place(place, network_type='drive')
G = ox.project_graph(G)
hospitals = ox.pois_from_place(place, amenities=['hospital'])
coord_1 = (38.69950, -9.18767)
target_1 = ox.get_nearest_node(G, coord_1)
print(target_1)
nc = ['r' if node==target_1 else 'gray' for node in G.nodes()]
ns = [50 if node==target_1 else 1 for node in G.nodes()]
fig, ax = ox.plot_graph(G, node_size=ns, node_color=nc, node_zorder=2)
From this I get the following node: 4751061000
The plot is:
And the hospital is near the sea: