Added --airport-geojson.
This commit is contained in:
parent
9b65ea88dd
commit
421c43c044
@ -267,21 +267,46 @@
|
||||
v)))
|
||||
|
||||
|
||||
(defn closest-airport [config lat lon]
|
||||
(p/let [results (pelias/nearby (:pelias config)
|
||||
(defn nearby-airports
|
||||
([config lat lon]
|
||||
(nearby-airports config lat lon {}))
|
||||
([config lat lon options]
|
||||
(p/let [radius (or (:radius options) 7)
|
||||
results (pelias/nearby (:pelias config)
|
||||
lat lon
|
||||
{:categories "transport:air:aerodrome"
|
||||
:boundary.circle.radius 7})
|
||||
:boundary.circle.radius radius})
|
||||
blocklist (get-in config [:airport :blocklist] [])
|
||||
blocklist-patterns (map #(re-pattern (str "(?i)" %)) blocklist)
|
||||
_ (println blocklist-patterns)]
|
||||
blocklist-patterns (map #(re-pattern (str "(?i)" %)) blocklist)]
|
||||
(->> (:features results)
|
||||
(remove (fn [airport] (some #(re-find % (get-in airport [:properties :label]))
|
||||
blocklist-patterns)))
|
||||
blocklist-patterns)))))))
|
||||
|
||||
|
||||
(defn closest-airport [config lat lon]
|
||||
(p/let [airports (nearby-airports config lat lon)]
|
||||
(->> airports
|
||||
(sort-by #(get-in % [:properties :distance]))
|
||||
first)))
|
||||
|
||||
|
||||
(defn airport-geojson [config]
|
||||
(p/let [airport->feature (fn [a]
|
||||
(let [props (:properties a)]
|
||||
{:type "Feature"
|
||||
:properties {:shape "Circle"
|
||||
:radius (* 1000 (:minimum-airport-distance-km config))
|
||||
:name (:label props)}
|
||||
:geometry {:type "Point"
|
||||
:coordinates (-> a :geometry :coordinates)}}))
|
||||
lat (:lat config)
|
||||
lon (:lon config)
|
||||
airports (nearby-airports config lat lon {:radius (+ (:radius-km config)
|
||||
(:minimum-airport-distance-km config))})]
|
||||
{:type "FeatureCollection"
|
||||
:features (map airport->feature airports)}))
|
||||
|
||||
|
||||
(defn log-table [table keys]
|
||||
(let [s (with-out-str (pprint/print-table keys table))
|
||||
lines (string/split-lines s)]
|
||||
@ -638,13 +663,30 @@
|
||||
(.option "--secrets <path>" "Path to the secrets yaml file" "secrets.yaml")
|
||||
(.option "--history <path>" "Path to history/state file" "advisorycircular.json")
|
||||
(.option "--log-prefix <prefix>" "Log prefix to use")
|
||||
(.option "--airport-geojson" "Generate airport GEOJSON and exit")
|
||||
(.parse (.-argv js/process)))
|
||||
(logging/set-log-prefix! (or (.-logPrefix commander) ""))
|
||||
(reset! log-prefix (or (.-logPrefix commander) ""))
|
||||
(if (.-airportGeojson commander)
|
||||
(p/try
|
||||
(p/let [base-config (if-let [config-path (.-config commander)]
|
||||
(util/read-config config-path)
|
||||
(if (fs/existsSync default-config-path)
|
||||
(util/read-config default-config-path)
|
||||
{}))
|
||||
cli-config (build-config-from-commander commander)
|
||||
config (build-config base-config cli-config {})
|
||||
geojson (airport-geojson config)]
|
||||
(println (.stringify js/JSON (clj->js geojson) nil " ")))
|
||||
(p/catch :default e
|
||||
(log-error "%s" e)
|
||||
(log-error "%s" (.-stack e))
|
||||
(.exit js/process 1)))
|
||||
(let [start-time (current-time)]
|
||||
;; If --config-path is specified, definitely try to read that
|
||||
;; file. Otherwise, only read config.yaml if it exists.
|
||||
(p/try
|
||||
(println "OMG DOING THIS")
|
||||
(p/let [base-config (if-let [config-path (.-config commander)]
|
||||
(util/read-config config-path)
|
||||
(if (fs/existsSync default-config-path)
|
||||
@ -689,7 +731,7 @@
|
||||
(p/catch :default e
|
||||
(log-error "%s" e)
|
||||
(log-error "%s" (.-stack e))
|
||||
(.exit js/process 1)))))
|
||||
(.exit js/process 1))))))
|
||||
|
||||
|
||||
;; (.on js/process "unhandledRejection"
|
||||
|
Loading…
Reference in New Issue
Block a user