   [n]
   (x/element :gco:Decimal {} (util/double->string n)))
 
-(def gml-id-state (atom 0))
-
-(defn gen-id
-  []
-  (str "geo-" (swap! gml-id-state inc)))
-
 (defmulti geometry->iso-geom
   "Returns content of a ISO MENDS extent element for an individual UMM
   spatial coverage geometry record. Dispatches on type."
-  type)
+  (fn [obj gen-id] (type obj)))
 
 ;;; Rendering gmd:geographicElement content
 
 (defmethod geometry->iso-geom cmr.spatial.point.Point
-  [point]
+  [point gen-id]
   (gmd-poly (x/element :gml:Point {:gml:id (gen-id)} (gml-pos point))))
 
 (defmethod geometry->iso-geom cmr.spatial.line_string.LineString
-  [{:keys [points]}]
+  [{:keys [points]} gen-id]
   (gmd-poly (x/element :gml:LineString {:gml:id (gen-id)}
                        (gml-poslist points))))
 
 (defmethod geometry->iso-geom cmr.spatial.polygon.Polygon
-  [polygon]
+  [polygon gen-id]
   (let [exterior (poly/boundary polygon)
         interior (poly/holes polygon)]
     (gmd-poly

                  (map #(x/element :gml:interior {} (gml-linear-ring (:points %))) interior))))))

(defmethod geometry->iso-geom cmr.spatial.mbr.Mbr
  [mbr]
  (x/element :gmd:EX_GeographicBoundingBox {}
             (x/element :gmd:westBoundLongitude {} (gco-decimal (:west mbr)))
             (x/element :gmd:eastBoundLongitude {} (gco-decimal (:east mbr)))

(defn spatial-coverage->extent-xml
  "Returns a sequence of ISO MENDS elements from the given SpatialCoverage."
  [{:keys [spatial-representation geometries]}]
  (let [id-state (atom 0)
        gen-id   (fn [] (str "geo-" (swap! id-state inc)))]
    (mapcat #(geometry->iso-xml spatial-representation % gen-id) geometries)))
