Przeglądaj źródła

Add example for working with OSM path data.

What I'd like to do is extracting "features" of street systems (such as
typical length of street segments, number of turns, angles), analyze the
results and use them to get a better idea how to procedurally generate
somewhat realistic looking street systems. (And to write more code in
clojure, of course.)
Lucas Stadler 12 lat temu
rodzic
commit
d1eb0d3afd
1 zmienionych plików z 34 dodań i 0 usunięć
  1. 34 0
      clj/paths.clj

+ 34 - 0
clj/paths.clj

@ -0,0 +1,34 @@
1
(ns paths
2
  "paths - Extracting paths from raw OSM data."
3
  (:use [clojure.xml  :as xml])
4
  (:use [clojure.repl :as r]))
5
6
(defn extract-nodes [osm]
7
  (let [nodes (filter #(= (:tag %) :node) osm)]
8
    (into {} (map (fn [node]
9
                    [(get-in node [:attrs :id]) node])
10
                  nodes))))
11
12
(defn get+
13
  "Extracts values of `ks` in `m` in the order the `ks` are given."
14
  [m ks]
15
  (reduce #(conj %1 (m %2)) [] ks))
16
17
(defn tags-as-map [osm-element]
18
  (let [tags (filter #(= (:tag %) :tag) (:content osm-element))]
19
    (into {} (map #(-> (get+ (:attrs %) [:k :v])
20
                       ((fn [[k v]]
21
                          [(keyword k) v])))
22
                  tags))))
23
24
(tags-as-map {:content [{:tag :tag, :attrs {:k :hey, :v 1}}, {:tag :tag, :attrs {:k :there, :v 2}}]})
25
26
(defn dev-prepare []
27
  (println "; reading in data/Leipzig_highways.osm...")
28
  (def leipzig
29
    (xml/parse "data/Leipzig_highways.osm"))
30
  (println ";=> availlable in `leipzig`")
31
  (println "; extracting nodes...")
32
  (def leipzig-nodes
33
    (extract-nodes {:content leipzig}))
34
  (println "; => availlable in `leipzig-nodes`"))