Files
yongestreet/scripts/to-geojson.clj
T
2025-01-02 13:12:38 -05:00

37 lines
1.2 KiB
Clojure

(require '[babashka.process :refer [shell process exec]]
'[clojure.string :as strings]
'[babashka.cli :as cli])
(defn extract-data [file]
(let [data (slurp file)
geojson (shell {:out :string :continue true :in data} "poly2geojson")
city-name (subs file
(inc (strings/last-index-of file "/"))
(strings/last-index-of file "_"))]
{:originalFile file
:geojson (some-> geojson
:out
(json/parse-string true)
:geometry
json/generate-string)
:province "québec"
:cityName city-name}))
(defn extract-osm-pbf [osm-file file]
(let [output-file (strings/replace file ".poly" ".osm.pbf")]
(println "Processing " file " file to " output-file)
(shell {:continue true}
"osmosis"
"--read-pbf-fast" (str "file=" osm-file)
"--bounding-polygon"
(str"file=" file)
"--write-pbf"
(str "file=" output-file))))
(def opts (cli/parse-opts *command-line-args* {:coerce {:paths []}}))
(doall (pmap
#(extract-osm-pbf (:osm-file opts) %)
(:paths opts)))