Skip to content

Instantly share code, notes, and snippets.

@damionjunk
Created September 20, 2012 18:01
Show Gist options
  • Save damionjunk/3757402 to your computer and use it in GitHub Desktop.
Save damionjunk/3757402 to your computer and use it in GitHub Desktop.
Locates a long,lat given a pre-processed shape file
(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