~ihabunek/triglav

b3486b734cd9f0a7d951408e2bca028b5a40afa2 — Ivan Habunek 5 months ago 7e76fd2
Add Router.route_all
1 files changed, 17 insertions(+), 0 deletions(-)

M lib/triglav/osm/router.ex
M lib/triglav/osm/router.ex => lib/triglav/osm/router.ex +17 -0
@@ 1,6 1,23 @@
defmodule Triglav.Osm.Router do
  alias Geo.LineString
  alias Triglav.Schemas.Osmosis.Way
  alias Triglav.Zet.Osmosis

  def route_all() do
    relations = Osmosis.list_public_transport_relations(type: "route", members: true)
    ways = Osmosis.list_ways(relations) |> Map.new(&{&1.id, &1})

    linestrings =
      for relation <- relations do
        relation.members
        |> Enum.filter(&(&1.member_type == "W"))
        |> Enum.filter(&(&1.member_role == ""))
        |> Enum.map(&Map.fetch!(ways, &1.member_id))
        |> route_ways()
      end

    Enum.zip(relations, linestrings)
  end

  defmodule AnnotatedWay do
    defstruct [:way, :direction, :node_ids, :linestring]