Polygonize airport circles in geojson. Support add'l airports in config.

This commit is contained in:
John Wiseman 2020-10-28 20:46:31 -07:00
parent 214e025af7
commit 9b784526af
3 changed files with 70 additions and 19 deletions

31
package-lock.json generated
View File

@ -14,6 +14,37 @@
"kuler": "^2.0.0" "kuler": "^2.0.0"
} }
}, },
"@turf/circle": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/@turf/circle/-/circle-6.0.1.tgz",
"integrity": "sha512-pF9XsYtCvY9ZyNqJ3hFYem9VaiGdVNQb0SFq/zzDMwH3iWZPPJQHnnDB/3e8RD1VDtBBov9p5uO2k7otsfezjw==",
"requires": {
"@turf/destination": "6.x",
"@turf/helpers": "6.x"
}
},
"@turf/destination": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/@turf/destination/-/destination-6.0.1.tgz",
"integrity": "sha512-MroK4nRdp7as174miCAugp8Uvorhe6rZ7MJiC9Hb4+hZR7gNFJyVKmkdDDXIoCYs6MJQsx0buI+gsCpKwgww0Q==",
"requires": {
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
}
},
"@turf/helpers": {
"version": "6.1.4",
"resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-6.1.4.tgz",
"integrity": "sha512-vJvrdOZy1ngC7r3MDA7zIGSoIgyrkWcGnNIEaqn/APmw+bVLF2gAW7HIsdTxd12s5wQMqEpqIQrmrbRRZ0xC7g=="
},
"@turf/invariant": {
"version": "6.1.2",
"resolved": "https://registry.npmjs.org/@turf/invariant/-/invariant-6.1.2.tgz",
"integrity": "sha512-WU08Ph8j0J2jVGlQCKChXoCtI50BB3yEH21V++V0T4cR1T27HKCxkehV2sYMwTierfMBgjwSwDIsxnR4/2mWXg==",
"requires": {
"@turf/helpers": "6.x"
}
},
"@types/mime-types": { "@types/mime-types": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz", "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz",

View File

@ -6,6 +6,7 @@
"shadow-cljs": "^2.11.5" "shadow-cljs": "^2.11.5"
}, },
"dependencies": { "dependencies": {
"@turf/circle": "^6.0.1",
"canvas": "^2.6.1", "canvas": "^2.6.1",
"commander": "^4.0.1", "commander": "^4.0.1",
"geolib": "^3.2.0", "geolib": "^3.2.0",

View File

@ -1,5 +1,6 @@
(ns lemondronor.advisorycircular (ns lemondronor.advisorycircular
(:require (:require
["@turf/circle" :default turf-circle]
["canvas" :as canvas] ["canvas" :as canvas]
[cemerick.url :as c-url] [cemerick.url :as c-url]
["commander" :as commander] ["commander" :as commander]
@ -418,20 +419,37 @@
v))) v)))
;; Returns airports defined in the config.
(defn additional-airports [config lat lon]
;; Get airports from config and annotate with :distance as though it
;; was returned by a pelias query.
(map (fn [airport]
(let [a-lon (get-in airport [:geometry :coordinates 0])
a-lat (get-in airport [:geometry :coordinates 1])
distance (geo/distance {:lat lat :lon lon}
{:lat a-lat :lon a-lon})]
(assoc-in airport [:properties :distance] distance)))
(-> config :airports :additional)))
(defn nearby-airports (defn nearby-airports
([config lat lon] ([config lat lon]
(nearby-airports config lat lon {})) (nearby-airports config lat lon {}))
([config lat lon options] ([config lat lon options]
(p/let [radius (or (:radius options) 7) (p/let [radius (or (:radius options) 7)
results (pelias/nearby (:pelias config) pelias-results (pelias/nearby (:pelias config)
lat lon lat lon
{:categories "transport:air:aerodrome" {:categories "transport:air:aerodrome"
:boundary.circle.radius radius}) :boundary.circle.radius radius})
additional-results (additional-airports config lat lon)
_ (log-info "Pelias airport results: %s" pelias-results)
_ (log-info "Additional airports from config: %s" additional-results)
results (concat (:features pelias-results) additional-results)
blocklist (get-in config [:airport :blocklist] []) blocklist (get-in config [:airport :blocklist] [])
blocklist-patterns (map #(re-pattern (str "(?i)" %)) blocklist)] blocklist-patterns (map #(re-pattern (str "(?i)" %)) blocklist)]
(->> (:features results) (remove (fn [airport] (some #(re-find % (get-in airport [:properties :label]))
(remove (fn [airport] (some #(re-find % (get-in airport [:properties :label])) blocklist-patterns))
blocklist-patterns))))))) results))))
(defn closest-airport [config lat lon] (defn closest-airport [config lat lon]
@ -444,12 +462,14 @@
(defn airport-geojson [config] (defn airport-geojson [config]
(p/let [airport->feature (fn [a] (p/let [airport->feature (fn [a]
(let [props (:properties a)] (let [props (:properties a)]
{:type "Feature" (js->clj
:properties {:shape "Circle" (turf-circle (clj->js (-> a :geometry :coordinates))
:radius (* 1000 (:minimum-airport-distance-km config)) (:minimum-airport-distance-km config)
:name (:label props)} (clj->js
:geometry {:type "Point" {:units "kilometers"
:coordinates (-> a :geometry :coordinates)}})) :properties {:type "airport"
:name (:label props)}}))
:keywordize-keys true)))
lat (:lat config) lat (:lat config)
lon (:lon config) lon (:lon config)
airports (nearby-airports config lat lon {:radius (+ (:radius-km config) airports (nearby-airports config lat lon {:radius (+ (:radius-km config)
@ -457,12 +477,11 @@
{:type "FeatureCollection" {:type "FeatureCollection"
:features (conj :features (conj
(map airport->feature airports) (map airport->feature airports)
{:type "Feature" (turf-circle (clj->js [(:lon config) (:lat config)])
:properties {:shape "Circle" (:radius-km config)
:radius (* 1000 (:radius-km config)) (clj->js
:name "Center"} {:units "kilometers"
:geometry {:type "Point" :properties {:type "coverage"}})))}))
:coordinates [(:lon config) (:lat config)]}})}))
(defn log-table [table keys] (defn log-table [table keys]