 
 
 
-   (defn to-nodes4j [results]
-        (into []
-           (map
-             #(get %1 "resultset")
-             results)))
-
-
-   (defn to-maps4j [results]
-        (into []
-           (map
-             #(:data (get %1 "resultset"))
-             results)))
-
-
-   (defn table4j [table-name]
-     (to-maps4j
-         (cy/tquery "START resultset=node:types('type:*') where resultset.type={type} RETURN resultset"
-                    {:type table-name})))
-
-
-
-   (defn nodes4j [table-name]
-     (to-nodes4j
-         (cy/tquery "START resultset=node:types('type:*') where resultset.type={type} RETURN resultset"
-                    {:type table-name})))
 
 
 
 
-   (defn make4j [node]
-      (if (:type node)
-         (let [
-                 node     (nn/create node)
-              ]
-              (nn/add-to-index (:id node)  (:name neo4j-type-index) "type" (:type node))
-         )
-         (throw (new java.lang.Exception "needs a type"))
-      )
-   )
+(defn to-maps4j [results]
+  (into []
+        (map
+         #(:data (get %1 "resultset"))
+         results)))
 
 
 
-   ;(make4j {:type "place" :name "Moscow"})
+
+(defn table4j [table-name]
+  (to-maps4j
+   (cy/tquery "START resultset=node:types('type:*') where resultset.type={type} RETURN resultset"
+              {:type table-name})))
 
 
 
-   ;(table4j "place")
-
-   ;(nodes4j "place")
-(comment let [amy (nn/create {:username "amy"})
-        bob (nn/create {:username "bob"})
-        _   (nrl/create amy bob :friend {:source "college"})]
-    (println (nrl/incoming-for bob :types [:friend])))
-
-
-(def layer (nsp/add-simple-point-layer "food4"))
-
-;layer
-
-
-;(nsp/add-simple-point-layer layer 0.1 0.1)
-
-(def mcd (nn/create {:name "mcDonalds"
-                     ;:wkt "POINT(51.6306,-0.80029)"
-                     :lat "lat" :lon "lon"}))
 
 
 
-(comment nsp/add-simple-point-layer
-     layer
-    "lat" "lon")
 
-;(nsp/find-within-distance layer 51.6306 -0.80029 5)
+
+(defn make4j [node]
+  (if (:type node)
+    (let [
+          node     (nn/create node)
+          ]
+      (nn/add-to-index (:id node)  (:name neo4j-type-index) "type" (:type node))
+      )
+    (throw (new java.lang.Exception "needs a type"))
+    )
+  )
+
+
+
+(make4j {:type "place" :name "Moscow"})
+
+
+
+(table4j "place")
+
+
+
+
 
 
 (defn- spatial-location-for




(defn get-from-neo [params]
    {:value (into []
         (let [amy (nn/create {:username "amy" :age 27})
                bob (nn/create {:username "bob" :age 28})
                _   (nrl/create amy bob :friend {:source "college"})
                res (cy/tquery "START x = node({ids}) RETURN x.username, x.age" {:ids (map :id [amy bob])})]
            res)
          )})


;(get-from-neo nil)








        payload  (json/decode body true)]
    (map instantiate-node-from payload)))





(defn add-simple-point-layer [lname]
  (nsp/add-simple-point-layer
   lname "lat" "lon"))


(add-simple-point-layer "pl")





(nsp/find-within-distance "pl" 51.6306 -0.80029 50000)




(defn add-node-to-layer
  "Add a node with the appropriate latitude and longitude properties to the given layer"
  [node layer]
  (first (post-spatial "addNodeToLayer" {:layer layer
                                         :node  (node-location-for rest/*endpoint* (:id node))
                                         })))


(defn add-to-simple-layer [nname lat lon layer]
  (let [
        node          (nn/create {:name nname :lat lat :lon lon})
        ]
    (add-node-to-layer node layer )
  )
)

(defn get-layer
  "Add a new point layer to the spatial index"
  ([layer]
     (first (post-spatial "getLayer" {:layer layer}))))

(get-layer "pl")


(add-to-simple-layer "McDonalds" -10.1 -1.0 "pl")

(def wkt-point (nn/create {:name "mcDonalds" :lat -1.1 :lon -1.1 }) )

;(add-node-to-layer (:location-uri  wkt-point) "zoo5" )

(defn find-within-distance
  "Find all points in the layer within a given distance of the given point"
  [layer point-x point-y distance-in-km]
  (post-spatial "findGeometriesWithinDistance"
                {:layer layer :pointX point-x :pointY point-y :distanceInKm distance-in-km}))


(defn find-names-within-distance [layer lat lon dist-km]
  (map (fn[x] (:name (:data x)))
    (find-within-distance layer lon lat dist-km)
  )
)

(find-names-within-distance "pl" -10.1 -1.1 100.1)



