Skip to content

Commit

Permalink
Appears to work.
Browse files Browse the repository at this point in the history
  • Loading branch information
klutometis committed Dec 1, 2011
1 parent d641dc0 commit c8bd4ad
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 59 deletions.
68 changes: 20 additions & 48 deletions TODO.org
Original file line number Diff line number Diff line change
Expand Up @@ -103,48 +103,35 @@
(import 'org.geotools.data.shapefile.ShapefileDataStore)
(import 'com.vividsolutions.jts.io.WKBWriter)

;;; This doesn't work, since it doesn't redefine it for clojure.core.
;;; This doesn't work, since it doesn't redefine it in clojure.core or
;;; tools.cli. Can we intern it elsewhere?
;;; <http://stackoverflow.com/a/4599444>
(defmethod print-method AFunction
[f writer]
(print-simple (:doc (meta f)) writer))

(def eval-string
(λ [string]
((comp eval read-string) string)))

(defmacro source-fn [name function]
(defmacro def-monadic [name function]
"Implements a monadic function whose toString is the source of the
function itself."
`(def ~name
(reify IFn
(toString [this] (str (quote ~function)))
(invoke [this arg1#] (~function arg1#)))))

;; (def default-feature-name
;; (reify clojure.lang.IFn
;; (toString [this] "euohn toeuthnueothnueohn teouthn oeuhn toeuoeuthn")
;; (invoke [this feature]
;; ((λ [feature]
;; (.getAttribute feature "NAME10"))
;; feature))))
(def eval-string
(λ [string]
((comp eval read-string) string)))

(source-fn default-feature-name
(def-monadic default-feature-name
(λ [feature]
(.getAttribute feature "NAME10")))

(debug
(with-meta
(λ [feature]
(.getAttribute feature "NAME10"))
{:doc "harro"})
(class (with-meta
(λ [feature]
(.getAttribute feature "NAME10"))
{:doc "harro"})))

(def default-feature-geometry
(def-monadic default-feature-geometry
(λ [feature]
(.getDefaultGeometry feature)))

(def default-feature-filter (constantly true))
(def-monadic default-feature-filter
(constantly true))

(let [writer (new WKBWriter)]
(def print-shape-map
Expand Down Expand Up @@ -177,33 +164,13 @@
(let [[{feature-name :feature-name
feature-geometry :feature-geometry
feature-filter :feature-filter}
files]
(cli *command-line-args*
["-n" "--name" "Extract a name from a feature"
:name :feature-name
:parse-fn eval-string
:default (with-meta default-feature-name {:doc "harro"})]
["-g" "--geometry" "Extract a geometry from a feature"
:name :feature-geometry
:parse-fn eval-string
:default default-feature-geometry]
["-f" "--filter" "Filter features"
:name :feature-filter
:parse-fn eval-string
:default default-feature-filter])]
(print-shape-map feature-name
feature-geometry
feature-filter
files))

(let [[parameters
files
usage]
(cli *command-line-args*
["-n" "--name" "Extract a name from a feature"
:name :feature-name
:parse-fn eval-string
:default default-feature-name]
:default (with-meta default-feature-name {:doc "harro"})]
["-g" "--geometry" "Extract a geometry from a feature"
:name :feature-geometry
:parse-fn eval-string
Expand All @@ -213,7 +180,12 @@
:parse-fn eval-string
:default default-feature-filter])]
(if (empty? files)
(println usage)))
(println usage)
(print-shape-map feature-name
feature-geometry
feature-filter
files)))

#+END_SRC

Tool has parameters for name-extraction, geometry-extraction and
Expand Down
29 changes: 18 additions & 11 deletions src/shp_to_map/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@
(:use [debug.core :only (debug)]
[lambda.core :only (λ)]
[clojure.tools.cli :only (cli)])
(:import (java.net URLClassLoader URL)
(java.io File)
(org.geotools.data.shapefile ShapefileDataStore)
(com.vividsolutions.jts.io WKBWriter)
(clojure.lang IFn))
(:gen-class))

(import 'java.net.URLClassLoader)
(import 'java.net.URL)
(import 'java.io.File)

(import 'org.geotools.data.shapefile.ShapefileDataStore)
(import 'com.vividsolutions.jts.io.WKBWriter)

(def eval-string
(λ [string]
((comp eval read-string) string)))

(def default-feature-name
(defmacro def-monadic [name function]
"Implements a monadic function whose toString is the source of the
function itself."
`(def ~name
(reify IFn
(toString [this] (str (quote ~function)))
(invoke [this arg1#] (~function arg1#)))))

(def-monadic default-feature-name
(λ [feature]
(.getAttribute feature "NAME10")))

(def default-feature-geometry
(def-monadic default-feature-geometry
(λ [feature]
(.getDefaultGeometry feature)))

(def default-feature-filter (constantly true))
(def-monadic default-feature-filter
(constantly true))

(let [writer (new WKBWriter)]
(def print-shape-map
Expand Down Expand Up @@ -64,7 +71,7 @@
["-n" "--name" "Extract a name from a feature"
:name :feature-name
:parse-fn eval-string
:default default-feature-name]
:default (with-meta default-feature-name {:doc "harro"})]
["-g" "--geometry" "Extract a geometry from a feature"
:name :feature-geometry
:parse-fn eval-string
Expand Down

0 comments on commit c8bd4ad

Please sign in to comment.