         polygons (map (fn [{{coordinates :coordinates} :geometry}] coordinates) results)
         ;; collect all the polygon segments
         all-segments (mapcat
-                   (fn [polygon]
-                     (mapcat
-                       (fn [ring]
-                         (partition 2 1 ring))
-                       polygon))
-                   polygons)
+                       (fn [polygon]
+                         (mapcat
+                           (fn [ring]
+                             (partition 2 1 ring))
+                           polygon))
+                       polygons)
         ;; remove shared (duplicate) segments, since they can't be near a trottoir
         lonely-segments (dump-dups all-segments)
         ;; remove short segments, they usually are corners of bati. This is a problem with round structures TODO

  (:import [com.mongodb MongoOptions ServerAddress]
    org.bson.types.ObjectId))

(def db (mg/get-db (mg/connect) "agreable"))
(defn objectId-reader [key value]
  (if (= key :_id)

        :when (= freq 1)]            ;; this is the filter condition
   id))

;; perform a mongodb aggregation of $geoNear (just to get the document distances, increasing) and $geoIntersects
;; take the closest result of two requests, since shapes were separated in two collections
(defn closest-shape [perp radius]
  (let [ q
         (fn [coll]
           (mc/aggregate
            db
            coll
            [{
              "$geoNear" {
                          :near {:type "Point" :coordinates (first perp)}
                          :spherical true
                          :maxDistance radius
                          :distanceField "calculated_distance"
                          :query { :geometry { "$geoIntersects" { "$geometry" (:geometry (perp-lineString perp)) } }}
                          }}]))]
    (apply min-key #(if (nil? %) 10000 (:calculated_distance %)) (map (comp first q) ["t" "v"]))
    ))

(apply min-key identity (remove nil? [ nil 1]))

;;; Main function ;;;;;;;;;;;
(defn drawPerps []
  (let [nearQuery { :geometry { $near
                             { "$geometry" {
