   "Creates a single ring polygon with the given ordinates. Points must be in counter clockwise order.
   The polygon will be closed automatically."
   [& ords]
-  (let [polygon (p/polygon [(apply r/ords->ring ords)])
-        outer (-> polygon :rings first derived/calculate-derived)]
+  (let [polygon (derived/calculate-derived (p/polygon [(apply r/ords->ring ords)]))
+        outer (-> polygon :rings first)]
     (when (and (:contains-north-pole outer)
                (:contains-south-pole outer))
       (throw (Exception. "Polygon can not contain both north and south pole. Points are likely backwards.")))

        polygon-south-pole (polygon -45 -80, -135 -80, 135 -80, 45 -80, -45 -80)
        polygon-antimeridian (polygon 135 -10, -135 -10, -135 10, 135 10, 135 -10)
        polygon-near-sp (polygon 168.1075 -78.0047, 170.1569,-78.4112, 172.019,-78.0002, 169.9779,-77.6071, 168.1075 -78.0047)
        coll (d/ingest "PROV1" (dc/collection {:spatial-coverage (dc/spatial :geodetic)}))
        make-gran (fn [& polygons]
                    (d/ingest "PROV1" (dg/granule coll {:spatial-coverage (apply dg/spatial polygons)})))

        gran6 (make-gran polygon-north-pole)
        gran7 (make-gran polygon-south-pole)
        gran8 (make-gran polygon-antimeridian)
        gran9 (make-gran polygon-near-sp)
        gran10 (make-gran polygon-with-holes)]
    (index/refresh-elastic-index)
    (are [ords items]
         (let [found (search/find-refs :granule {:polygon (apply search-poly ords) })
               matches? (d/refs-match? items found)]
           (when (and (not matches?) spatial-viz-enabled)
             (println "Displaying failed granules and search area")
             (println "Found: " (pr-str found))
             (viz-helper/clear-geometries)
             (display-indexed-granules items)
             (display-search-area (apply polygon ords)))
           matches?)

         ;; Related the polygon with the hole
         ;; Inside holes
         [4.1,0.64,4.95,0.97,6.06,1.76,3.8,1.5,4.1,0.64] []
         [1.41,5.12,3.49,5.52,2.66,6.11,0.13,6.23,1.41,5.12] []
         ;; Partially inside a hole
         [3.58,-1.34,4.95,0.97,6.06,1.76,3.8,1.5,3.58,-1.34] [gran10]
         ;; Covers a hole
         [3.58,-1.34,5.6,0.05,7.6,2.33,2.41,2.92,3.58,-1.34] [gran10]
         ;; points inside both holes
         [4.44,0.66,5.4,1.35,2.66,6.11,0.13,6.23,4.44,0.66] [gran10]
         ;; completely covers the polygon with holes
         [-6.45,-3.74,12.34,-4.18,12,9.45,-6.69,9.2,-6.45,-3.74] [gran10 gran11]

         ;; Normal searching
         [10 10, 30 10, 30 20, 10 20, 10 10] [gran1 gran4]
         [173.34,-77.17, 171.41,-77.08, 170.64,-78.08, 173.71,-78.05, 173.34,-77.17] [gran9])))


