Created
September 20, 2012 18:01
-
-
Save damionjunk/3757402 to your computer and use it in GitHub Desktop.
Locates a long,lat given a pre-processed shape file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn locate-point | |
"Given a map of shapes see (process-shape-file), locate the entry that | |
contains the given lat/long, optionally filtered by keys." | |
([shapes long lat] (locate-point shapes lat long nil)) | |
([shapes long lat keys] | |
(let [locs (if keys (select-keys shapes keys) shapes) | |
point (.. JTSFactoryFinder (getGeometryFactory) | |
(createPoint (Coordinate. long lat))) | |
flocs (first | |
(filter (fn [x] | |
(let [geom (:geom (val x))] | |
(if (nil? geom) false (.contains geom point)))) | |
locs))] | |
(if flocs (val flocs))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment