Skip to content

Commit f88e7fc

Browse files
committed
switch back to GeoInterface.jl
1 parent 3c92143 commit f88e7fc

File tree

7 files changed

+38
-16
lines changed

7 files changed

+38
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = "0.3.1"
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
88
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
99
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
10-
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
10+
GeoInterfaceRecipes = "0329782f-3d07-4b52-b9f6-d3137cf03c7a"
1111
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1212
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
1313
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"

example.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using LightOSM, Plots
1+
using LightOSM, Plots, GeoInterfaceRecipes
22

33
g = graph_from_download(
44
:place_name,
@@ -8,8 +8,8 @@ g = graph_from_download(
88
sg = simplify_graph(g)
99

1010
# check for missing edges
11-
plot(g, color=:red, linewidth=0.8)
12-
plot!(edge_gdf(sg).geom, linewidth=1.1, color=:black)
11+
plot(g, color=:red, linewidth=0.8, size=(800, 800))
12+
plot!(sg, linewidth=1.1, color=:black)
1313
savefig("edge_validation")
1414

1515
# show original nodes

src/LightOSM.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ using LightXML
1616
using StaticArrays
1717
using SpatialIndexing
1818
using DataFrames
19-
using GeoInterface
20-
using GeometryBasics
19+
using GeoInterface: MultiLineString, LineString, Point
2120
using RecipesBase
2221

2322
export GeoLocation,

src/geodataframes.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
GeometryBasics.Point(node::Node) = Point(node.location.lon, node.location.lat)
2-
GeometryBasics.LineString(way::Way) = LineString(Point.(way.nodes))
1+
Point(node::Node) = Point(node.location.lon, node.location.lat)
2+
LineString(g::AbstractOSMGraph, way::Way) = LineString(Point.(g.parent.nodes[i] for i in way.nodes))
33

44
function node_gdf(g::AbstractOSMGraph)
55
ids = collect(keys(g.nodes))
6-
return DataFrame(;id=ids, geom=Point.(values(g.nodes)))
6+
nodes = (g.nodes[id] for id in ids)
7+
return DataFrame(;id=ids, tags=getproperty.(nodes, :tags), geom=Point.(nodes))
78
end
89

910
function way_gdf(g::AbstractOSMGraph)
1011
ids = collect(keys(g.ways))
11-
return DataFrame(;id=ids, geom=LineString.(values(g.ways)))
12+
ways = (g.ways[id] for id in ids)
13+
return DataFrame(;id=ids, tags=getproperty.(ways, :tags), geom=LineString.(Ref(g), ways))
1214
end
1315

1416
function edge_gdf(g::SimplifiedOSMGraph)
1517
edge_ids = collect(keys(g.edges))
1618
geom = map(edge_ids) do edge
1719
path = g.edges[edge]
18-
reverse.(g.parent.node_coordinates[path])
20+
LineString(Point.(g.nodes[path]))
1921
end
2022
u, v, key = map(i -> getindex.(edge_ids, i), 1:3)
21-
return DataFrame(;u, v, key, geom=LineString.(geom))
23+
return DataFrame(;u, v, key, geom=geom)
2224
end

src/plotrecipes.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@ function aspect_ratio(g::AbstractOSMGraph)
55
end
66

77
RecipesBase.@recipe function f(g::AbstractOSMGraph)
8+
# way color and thickness
89
color --> :black
10+
linewdith --> 1.5
11+
# node color and size
12+
markercolor --> :blue
13+
markersize --> 2
914
aspect_ratio --> aspect_ratio(g)
10-
MultiLineString(way_gdf(g).geom)
15+
# plot ways
16+
@series begin
17+
seriestype := :path
18+
MultiLineString(way_gdf(g).geom)
19+
end
20+
21+
# plot nodes
22+
@series begin
23+
seriestype := :scatter
24+
node_gdf(g).geom
25+
end
1126
end

src/simplification.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ The geometry of the contracted nodes is kept in the edge_gdf DataFrame
6969
function simplify_graph(g::OSMGraph{U, T, W}) where {U, T, W}
7070
relevant_nodes = collect(endpoints(g.graph))
7171
n_relevant = length(relevant_nodes)
72+
nodes = Dict{T,Node{T}}()
7273
graph = DiGraph(n_relevant)
7374
weights = similar(g.weights, (n_relevant, n_relevant))
7475
node_coordinates = Vector{Vector{W}}(undef, n_relevant)
@@ -79,9 +80,10 @@ function simplify_graph(g::OSMGraph{U, T, W}) where {U, T, W}
7980
for (new_i, old_i) in enumerate(relevant_nodes)
8081
index_mapping[old_i] = new_i
8182
node_coordinates[new_i] = g.node_coordinates[old_i]
82-
node = g.index_to_node[old_i]
83-
index_to_node[new_i] = node
84-
node_to_index[node] = new_i
83+
osm_id = g.index_to_node[old_i]
84+
nodes[osm_id] = g.nodes[osm_id]
85+
index_to_node[new_i] = osm_id
86+
node_to_index[osm_id] = new_i
8587
end
8688

8789
edges = Dict{NTuple{3,U}, Vector{U}}()
@@ -106,6 +108,7 @@ function simplify_graph(g::OSMGraph{U, T, W}) where {U, T, W}
106108

107109
return SimplifiedOSMGraph(
108110
g,
111+
nodes,
109112
node_coordinates,
110113
node_to_index,
111114
index_to_node,

src/types.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ function Base.getproperty(g::OSMGraph, field::Symbol)
161161
elseif field === :node_to_highway
162162
Base.depwarn("`node_to_highway` field is deprecated, use `node_to_way` field instead", :getproperty)
163163
return getfield(g, :node_to_way)
164+
elseif field === :parent
165+
return g
164166
elseif field === :edge_to_highway
165167
Base.depwarn("`edge_to_highway` field is deprecated, use `edge_to_way` field instead", :getproperty)
166168
return getfield(g, :edge_to_way)
@@ -171,6 +173,7 @@ end
171173

172174
struct SimplifiedOSMGraph{U,T,W} <: AbstractOSMGraph{U,T,W}
173175
parent::OSMGraph{U,T,W}
176+
nodes::Dict{T,Node{T}}
174177
node_coordinates::Vector{Vector{W}} # needed for astar heuristic
175178
node_to_index::OrderedDict{T,U}
176179
index_to_node::OrderedDict{U,T}

0 commit comments

Comments
 (0)