OSMnx has no attribute 'extended_stats'
Trying to create the GPX file from the results but get an error that OSMnx has no attribute 'extended_stats' Looking at the docs for OSMnx it seems extended_stats doesn't exist, unable to see if this has been deprecated either.
AH ok I found this in the git history. extended_stats did exist within stats.py with the following message:
msg = (
"The extended_stats function has been deprecated and will be removed in a "
"future release. Use NetworkX directly for extended topological measures."
)
OK I updated this part to get the info straight from networkx. the following code will create the GPX file
from libs.gpx_formatter import TEMPLATE, TRACE_POINT
from datetime import datetime
...
# Route statistics from OSMnx
Gs = ox.utils_graph.get_largest_component(org_graph, strongly=True)
length_func = nx.single_source_dijkstra_path_length
sp = {source: dict(length_func(Gs, source, weight="length")) for source in Gs.nodes}
eccentricity = nx.eccentricity(Gs, sp=sp)
center = nx.center(Gs, e=eccentricity)
center_node = org_graph.nodes[center[0]]
trace_points = "\n\t\t\t".join([TRACE_POINT.format(
lat=lat, lon=lon, id=i, timestamp=datetime.now().isoformat()
) for i, (lat, lon) in enumerate(coordinates_path)])
gpx_payload = TEMPLATE.format(
name="Name your everystreet route",
trace_points=trace_points,
center_lat=center_node["y"],
center_lon=center_node["x"]
)
with open("gpx_output.gpx", "w") as f:
f.write(gpx_payload)
Hi @joefizz,
Thanks for looking at that, it seems that a new version of networkx was released and changed the object. As far as I can see you have fix the problem, would you mind to create a PR for it?
Thanks again!
Matej
For everyone looking for a workaround: if you want to create a GPX, the extended_stats is solely used for calculating the center of the route. I changed it to just use the first track point as waypoint.
from libs.gpx_formatter import TEMPLATE, TRACE_POINT
from datetime import datetime
...
coordinates_path = convert_final_path_to_coordinates(org_graph, final_path)
trace_points = "\n\t\t\t".join([TRACE_POINT.format(
lat=lat, lon=lon, id=i, timestamp=datetime.now().isoformat()
) for i, (lat, lon) in enumerate(coordinates_path)])
gpx_payload = TEMPLATE.format(
name="everystreet route",
trace_points=trace_points,
center_lat=coordinates_path[0][0],
center_lon=coordinates_path[0][1]
)
with open("gpx_output.gpx", "w") as f:
f.write(gpx_payload)