little morning programming
This commit is contained in:
1 parent
71389d1f62
commit
fcde91436a
4 files changed
+143
-65
No files matched your search
+25
-25
@@ -2,35 +2,35 @@
|
||||
'[clojure.string :as strings]
|
||||
'[babashka.cli :as cli])
|
||||
|
||||
(defn osmosis-command [osm-file poly-file output-file]
|
||||
["osmosis"
|
||||
"--read-pbf-fast" (str "file=" osm-file)
|
||||
"--bounding-polygon"
|
||||
(str"file=" poly-file)
|
||||
"--write-pbf"
|
||||
(str "file=" output-file)])
|
||||
|
||||
(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 osmium-command [osm-file poly-file output-file]
|
||||
["osmium"
|
||||
"extract"
|
||||
"-p"
|
||||
poly-file
|
||||
osm-file
|
||||
"-o"
|
||||
output-file])
|
||||
|
||||
(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))))
|
||||
(defn extract-osm-pbf [osm-file poly-file]
|
||||
(let [output-file (strings/replace poly-file ".poly" ".osm.pbf")
|
||||
cmd (osmium-command osm-file poly-file output-file)]
|
||||
(println "Processing " poly-file " file to " output-file)
|
||||
(println cmd)
|
||||
(apply shell (into [{:continue false}] cmd))))
|
||||
|
||||
(def opts (cli/parse-opts *command-line-args* {:coerce {:paths []}}))
|
||||
|
||||
(doall (pmap
|
||||
(println "ok")
|
||||
(println opts)
|
||||
|
||||
(doall (map
|
||||
#(extract-osm-pbf (:osm-file opts) %)
|
||||
(:paths opts)))
|
||||
Reference in new issue
Block a user