Skip to content

Commit 0b55c94

Browse files
committed
use GeometryBasics implementation because GeoInterface no longer provides implementations for geo types
1 parent 023297e commit 0b55c94

File tree

5 files changed

+33
-60
lines changed

5 files changed

+33
-60
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +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"
1011
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1112
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
1213
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"

example.jl

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,23 @@
1-
using LightOSM, GeoInterface, Plots, DataFrames
2-
using ArchGDAL: createmultilinestring
1+
using LightOSM, Plots
32

43
g = graph_from_download(
5-
:place_name, place_name="moabit, berlin germany",
4+
:place_name,
5+
place_name="tiergarten, berlin germany",
66
network_type=:bike
77
)
8-
# reverse coordinates for plotting
9-
reverse!.(g.node_coordinates)
10-
11-
g_simple, weights, node_gdf, edge_gdf = simplify_graph(g)
12-
13-
# join edges in mulitlinestring for faster plotting
14-
all_edges = createmultilinestring(coordinates.(edge_gdf.geom))
15-
16-
# node validation
17-
18-
# nodes from original graph
19-
plot(all_edges, color=:black, size=(1200,800))
20-
scatter!(first.(g.node_coordinates), last.(g.node_coordinates), color=:red)
21-
22-
# nodes from simplified graph
23-
plot(all_edges, color=:black, size=(1200,800))
24-
scatter!(node_gdf.geom, color=:green)
25-
26-
27-
# edge validation
28-
29-
function highway_gdf(osmg::OSMGraph)
30-
function _geometrize_way(way)
31-
createlinestring(map(id -> coordinates(osmg.nodes[id]), way.nodes))
32-
end
33-
geom = map(way -> _geometrize_way(way), values(osmg.highways))
34-
return DataFrame(; id = collect(keys(osmg.highways)), geom)
35-
end
36-
8+
sg = simplify_graph(g)
9+
10+
# check for missing edges
11+
plot(g, color=:red, linewidth=0.8)
12+
plot!(edge_gdf(sg).geom, linewidth=1.1, color=:black)
13+
savefig("edge_validation")
14+
15+
# show original nodes
16+
plot(sg)
17+
plot!(node_gdf(g).geom, color=:red, markersize=2.2)
18+
savefig("original_nodes")
19+
20+
# show relevant nodes
21+
plot(sg)
22+
plot!(node_gdf(sg).geom, color=:green, markersize=2.2)
23+
savefig("relevant_nodes")

src/LightOSM.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using StaticArrays
1717
using SpatialIndexing
1818
using DataFrames
1919
using GeoInterface
20+
using GeometryBasics
2021
using RecipesBase
2122

2223
export GeoLocation,

src/geodataframes.jl

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
1-
coordinates(node::Node) = [node.location.lon, node.location.lat]
1+
GeometryBasics.Point(node::Node) = Point(node.location.lon, node.location.lat)
2+
GeometryBasics.LineString(way::Way) = LineString(Point.(way.nodes))
23

3-
function node_gdf(g::OSMGraph)
4+
function node_gdf(g::AbstractOSMGraph)
45
ids = collect(keys(g.nodes))
5-
geom = map(ids) do id
6-
coordinates(g.nodes[id])
7-
end
8-
return DataFrame(;id=ids, geom=Point.(geom))
9-
end
10-
11-
function way_gdf(g::OSMGraph)
12-
ids = collect(keys(g.highways))
13-
_way_coordinates(way) = map(way.nodes) do id
14-
coordinates(g.nodes[id])
15-
end
16-
geom = map(id -> _way_coordinates(g.highways[id]), ids)
17-
return DataFrame(;id=ids, geom=LineString.(geom))
6+
return DataFrame(;id=ids, geom=Point.(values(g.nodes)))
187
end
198

20-
function node_gdf(sg::SimplifiedOSMGraph)
21-
ids = collect(keys(sg.node_to_index))
22-
geom = map(ids) do id
23-
coordinates(sg.parent.nodes[id])
24-
end
25-
return DataFrame(;id=ids, geom=Point.(geom))
9+
function way_gdf(g::AbstractOSMGraph)
10+
ids = collect(keys(g.ways))
11+
return DataFrame(;id=ids, geom=LineString.(values(g.ways)))
2612
end
2713

28-
way_gdf(sg::SimplifiedOSMGraph) = way_gdf(sg.parent)
29-
30-
function edge_gdf(sg::SimplifiedOSMGraph)
31-
edge_ids = collect(keys(sg.edges))
14+
function edge_gdf(g::SimplifiedOSMGraph)
15+
edge_ids = collect(keys(g.edges))
3216
geom = map(edge_ids) do edge
33-
path = sg.edges[edge]
34-
reverse.(sg.parent.node_coordinates[path])
17+
path = g.edges[edge]
18+
reverse.(g.parent.node_coordinates[path])
3519
end
3620
u, v, key = map(i -> getindex.(edge_ids, i), 1:3)
3721
return DataFrame(;u, v, key, geom=LineString.(geom))

src/plotrecipes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ end
77
RecipesBase.@recipe function f(g::AbstractOSMGraph)
88
color --> :black
99
aspect_ratio --> aspect_ratio(g)
10-
MultiLineString(GeoInterface.coordinates.(way_gdf(g).geom))
10+
MultiLineString(way_gdf(g).geom)
1111
end

0 commit comments

Comments
 (0)