Skip to content

Instantly share code, notes, and snippets.

@gavinheavyside
Created May 26, 2010 20:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavinheavyside/415029 to your computer and use it in GitHub Desktop.
Save gavinheavyside/415029 to your computer and use it in GitHub Desktop.
(ns geotools.shape-viewer
(:import [org.geotools.data CachingFeatureSource FeatureSource FileDataStore FileDataStoreFinder])
(:import [org.geotools.map DefaultMapContext MapContext])
(:import [org.geotools.swing JMapFrame])
(:import [org.geotools.swing.data JFileDataStoreChooser]))
(defn show-shapefile
"Prompts the user for a shapefile and displays its content"
[]
(if-let [shapefile (JFileDataStoreChooser/showOpenFile "shp" nil)]
(let [fs (.getFeatureSource (FileDataStoreFinder/getDataStore shapefile))]
(doto (DefaultMapContext.)
(.setTitle "Quickstart")
(.addLayer fs nil)
(JMapFrame/showMap)))))
(defn show-shapefile-cached
"Prompts the user for a shapefile and displays its content.
Uses memory-based cache to speed up display"
[]
(if-let [shapefile (JFileDataStoreChooser/showOpenFile "shp" nil)]
(let [fs (.getFeatureSource (FileDataStoreFinder/getDataStore shapefile))
cache (CachingFeatureSource. fs)]
(doto (DefaultMapContext.)
(.setTitle "Quickstart")
(.addLayer cache nil)
(JMapFrame/showMap)))))
(defproject geotools-something-like-this-perhaps "1.0.0-SNAPSHOT"
:description "FIXME: write"
:repositories {"osgeo-geotools" "http://download.osgeo.org/webdav/geotools"}
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[org.geotools/gt-main "2.7-M3"]dd
[org.geotools/gt-shapefile "2.7-M3"]])
@apatil
Copy link

apatil commented Nov 22, 2010

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment