osmnx: get_nearest_node returning distant nodes
The .get_nearest_node
method returns a node within the graph but nowhere near the original point. The point below returns a node here. May be a projection issue but projecting the graph differently didn’t fix it.
Using OSMnx 0.5.2dev in python 2.7 on a Mac.
import osmnx as ox, networkx as nx
ox.config(log_console=True, use_cache=True)
G = ox.graph_from_place('Buffalo, New York, USA', network_type='walk')
orig_point = (42.99618326, -78.957126)
orig_node = ox.get_nearest_node(G, orig_point)
print orig_node
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (13 by maintainers)
Commits related to this issue
- fixes #71 — committed to gboeing/osmnx by gboeing 7 years ago
@kaseyklimes see the documentation for this function: if the graph is projected, you should use the ‘euclidean’
method
instead of the default ‘greatcircle’ method. Also, note that thepoint
argument is passed as a tuple of (lat, lng) if in degrees or (y, x) if in projected planar units such as meters. This is kind of weird, but I think it’s necessary: we consistently treat degree coordinates as (lat, lng) and there may be times when we want to calculate euclidean distances between them. In which case, both algorithms (euclidean and great circle) must accept a consistent point format… (lat, lng) is equivalent to (y, x).So, if we specify a (y, x) point and use the euclidean method:
Prints 0.454… so the nearest node is only half a meter from the point you specified.
Clarified usage in 29005df and dd32fa2
@kuanb that’s right. Great circle distance measures distances along the surface of a sphere while euclidean distance measures it along a two dimensional plane. Lat-long data is in spherical units of degrees: it represents points on the surface of a sphere (or an approximate spheroid). If you project your lat-long data to two-dimensional planar units such as meters, great circle distance no longer makes sense: you need to use a planar metric such as Euclidean distance.
RTFM Kasey, RTFM. Thanks Geoff 👍