Skip to content

Commit

Permalink
Using reduce-features
Browse files Browse the repository at this point in the history
  • Loading branch information
klutometis committed Dec 1, 2011
1 parent b6fa6f6 commit 3161f6e
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions TODO.org
Expand Up @@ -134,8 +134,6 @@
(def-monadic default-feature-filter
(constantly true))

;;; This may even be prohibitive; why can't we iterate over
;;; getFeatures?
(def features
(λ [shapefile]
(.features
Expand All @@ -144,10 +142,14 @@
(new ShapefileDataStore
(.toURL (.toURI (new File shapefile)))))))))

;; (def reduce-features
;; (λ [f val features]
;; (loop [val val]
;; (let [feature (.hasNext)]))))
(def reduce-features
(λ [f val features]
(with-open [features features]
(loop [val val]
(if (.hasNext features)
(let [feature (.next features)]
(recur (f val feature)))
val)))))

(let [writer (new WKBWriter)]
(def geometry->hex
Expand All @@ -159,19 +161,18 @@
(doseq [[name geometries]
(reduce
(λ [name->geometries file]
(let [features (features file)]
(loop [name->geometries name->geometries]
(if (.hasNext features)
(let [feature (.next features)]
(let [hex (geometry->hex (feature-geometry feature))
name (feature-name feature)]
(recur (assoc name->geometries
(reduce-features
(λ [name->geometries feature]
(let [name (feature-name feature)
hex (geometry->hex (feature-geometry feature))]
(assoc name->geometries
name
(cons hex
(get name->geometries
name
(cons hex
(get name->geometries
name
'()))))))
name->geometries))))
'())))))
name->geometries
(features file)))
{}
files)]
(printf "%s\t%s\n" name (apply str (interpose "|" geometries))))))
Expand Down

0 comments on commit 3161f6e

Please sign in to comment.