Last active
November 11, 2017 12:16
-
-
Save rastandy/064e90c63c5a6e5e2fe4715621756978 to your computer and use it in GitHub Desktop.
Clojure specs for a geographical bounding box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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