Skip to content

Instantly share code, notes, and snippets.

@rastandy
Last active November 11, 2017 12:16
Show Gist options
  • Save rastandy/064e90c63c5a6e5e2fe4715621756978 to your computer and use it in GitHub Desktop.
Save rastandy/064e90c63c5a6e5e2fe4715621756978 to your computer and use it in GitHub Desktop.
Clojure specs for a geographical bounding box
(ns data-portal.specs.bbox
(:require [clojure.spec.alpha :as s]))
(s/def :geo/latitude (s/and number? #(<= -90 % 90)))
(s/def :geo/longitude (s/and number? #(<= -180 % 360)))
(s/def :geo/north :geo/latitude)
(s/def :geo/south :geo/latitude)
(s/def :geo/east :geo/longitude)
(s/def :geo/west :geo/longitude)
(s/def :bbox/bbox
(s/or :full (s/and (s/keys :req-un [:geo/north :geo/south :geo/east :geo/west])
#(<= (- (:east %) (:west %)) 360)
#(<= (:south %) (:north %))
#(<= (:west %) (:east %)))
:empty #(every? nil? (vals %))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment