DeloitteOptimalReality / LightOSM.jl

A Julia package for downloading and analysing geospatial data from OpenStreetMap APIs.
https://deloitteoptimalreality.github.io/LightOSM.jl/docs
Other
47 stars 12 forks source link

[WIP] Simplify Graph #58

Open rush42 opened 2 years ago

rush42 commented 2 years ago

This PR implements an algorithm for simplifying the topology of an OSMGraph object. It is adapted from osmnx.

This PR is work in progress, and a few issues have to be discussed.

TODO:

  1. the output format of the simplification procedure (rn it returns a DiGraph and two DataFrames: one for nodes and the other for edges (which also contains the edge geometry) )
  2. reference to the original OSM objects (an edge can consist of serveral ways)
  3. turn restrictions
  4. type stability and code generalization for types

Below is an example for Tiergarten district in Mitte, Berlin, Germany:

Before the simplification: nodes: 2976, egdes: 4727 before

After the simplification: nodes: 683, edges: 1384 after

I will upload an example script the following days.

mmiller-max commented 2 years ago

This is a great idea, thanks for working on it. Concerning your TODOs:

  1. the output format of the simplification procedure (rn it returns a DiGraph and two DataFrames: one for nodes and the other for edges (which also contains the edge geometry) )
  2. reference to the original OSM objects (an edge can consist of serveral ways)

I think it should return something like SimplifiedOSMGraph where the graph type and other parametric types match that of the input OSMGraph. This simplified graph could then contain then mapping between the original and new edge IDs. We could add something that gets the way IDs from the new edge IDs too.

We could add a parent type to SimplifiedOSMGraph and OSMGraph for the functions with which either graph works.

Ideally the NodeIDs should be the same as then we can use all the additional OSM data for them - are they?

  1. turn restrictions

Yep this is pretty important, but hopefully just a small extension to what you've got already.

  1. type stability and code generalization for types

Does my answer to 1 above remove all the instabilities, or do other functions need improving as well?

rush42 commented 2 years ago

I added the SimplifiedOSMGraph type and methods for generating "GeoDataFrames" either from OSMGraph or SimplifiedOSMGraph objects. Additional I added a small PlotRecipe for visualization.

The example below makes use of the above mentioned methods and was mainly for checking if every thing looks correct.

using LightOSM, Plots

g = graph_from_download(
    :place_name, 
    place_name="tiergarten, berlin germany",
    network_type=:bike
)
sg = simplify_graph(g)

# check for missing edges
plot(g, color=:red, linewidth=0.8)
plot!(edge_gdf(sg).geom, linewidth=1.1, color=:black)
savefig("edge_validation")

# show original nodes
plot(sg)
plot!(node_gdf(g).geom, color=:red, markersize=2.2)
savefig("original_nodes")

# show relevant nodes
plot(sg)
plot!(node_gdf(sg).geom, color=:green, markersize=2.2)
savefig("relevant_nodes")

Output:

this should only show black edges: edge_validation

original nodes: original_nodes

relevant noes: relevant_nodes

I will write some tests when I'll find the time to check if the topology is preserved correctly and if the weights are correct.

mmiller-max commented 2 years ago

Hey sorry for the delay, will try to review soon. It'd also be good for @captchanjack to take a look at this as it's a relatively big addition and I'm keen to know how it fits in with his thoughts for the package.

mmiller-max commented 2 years ago

It would be helpful to fix the merge conflicts via a rebase or merge - in particular the renaming of the field highway to way should be observed in the new graph. Once the conflicts are sorted I can kick off CI, it seems that GitHub won't let me do it before then.

rush42 commented 2 years ago

I've merged the changes, and added the edge_to_way dict to simplifiedOSMGraph.

mmiller-max commented 2 years ago

@rush42 Just wanted to say sorry we haven't got around to reviewing this yet. Hopefully someone will be able to soon!

ctlbau commented 1 year ago

Awesome PR! will this be merged soon? I've tried using as is but cannot get shortest_path calculations from SimplifiedOSMGraph

rush42 commented 5 months ago

@ctrebbau yes I haven't worked on the shortest path algorithms yet. And right now I can't find the time to do so. IMO it's the only thing missing, the rest should be implemented...