Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSMnx has no attribute 'extended_stats' #27

Open
joefizz opened this issue Dec 7, 2022 · 4 comments
Open

OSMnx has no attribute 'extended_stats' #27

joefizz opened this issue Dec 7, 2022 · 4 comments

Comments

@joefizz
Copy link

joefizz commented Dec 7, 2022

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.

@joefizz
Copy link
Author

joefizz commented Dec 7, 2022

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."
    )

@joefizz
Copy link
Author

joefizz commented Dec 7, 2022

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)

@matejker
Copy link
Owner

matejker commented Dec 8, 2022

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

@fm-sys
Copy link

fm-sys commented Oct 17, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants