How do I install it?
• Install Java
• Install Groovy
• Download GeoScript Groovy and put the
bin directory on your path
• https://github.com/jericks/geoscript-groovy/
releases
How do I learn it?
http://geoscript.org
http://geoscript.org/groovy/api/
Inline Scripts
(geoscript-groovy)
• One liners
• Interact with other command line tools
• geom, mapfart, ogr, ect…
• Read Standard Input (System.in.text)
• Write to Standard Output (println)
Scripts
web.groovy
(geoscript-groovy)
1 import com.sun.grizzly.http.embed.GrizzlyWebServer!
2 import com.sun.grizzly.http.servlet.ServletAdapter!
3 !
4 @Grab(group='com.sun.grizzly', module='grizzly-servlet-webserver',
version='1.9.10')!
5 def start() {!
6
println("Starting web server...")!
7
def server = new GrizzlyWebServer(8080, "web")!
8
def servlet = new ServletAdapter()!
9
servlet.contextPath = "/geoscript"!
10
servlet.servletInstance = new groovy.servlet.GroovyServlet()!
11
server.addGrizzlyAdapter(servlet, ["/geoscript"] as String[])!
12
server.start()!
13 }!
14 start()
Scripts
(geoscript-groovy)
• Larger multiline scripts
• Good for complex processing
• Record your workflow
• Can create command line tools, web
services, or desktop apps
• Use @Grab to get dependencies
Shell
(geoscript-groovysh)
Groovy Shell (2.1.9, JVM: 1.7.0_45)
Type 'help' or 'h' for help.
-------------------------------------------------------------------------------
groovy:000> import geoscript.workspace.PostGIS
===> [import geoscript.workspace.PostGIS]
groovy:000> postgis = new PostGIS("states",user: "jericks")
===> geoscript.workspace.PostGIS@7840df80
groovy:000> postgis.layers
===> [states]
groovy:000> states = postgis.get("states")
===> states
groovy:000> states.bounds
===> (-124.731422,24.955967,-66.969849,49.371735,EPSG:4326)
groovy:000> states.count
===> 49
groovy:000> states.eachFeature{ println it.geom.centroid }
POINT (-89.20368628698026 40.06397152717181)
POINT (-77.01592888814594 38.90248929357207)
POINT (-75.50090936853277 38.994999876971384)
POINT (-80.61424804312078 38.64111336139042)
Console
• Good for longer scripts (but not too long)
• Excellent preview (View -> Visualize Script
Results)
• Use it when rendering images, maps,
geometries
uDig
•
•
•
Done by Andrea Antonello and the UDig crew
•
http://prezi.com/wyopic4sinhg/geographic-scripting-inudig-user-friendly-desktop-internet-gis/
Part of the Spatial Toolbox
http://udig.github.io/docs/user/getting_started/GeoScript
%20Introduction.html
• http://www.slideshare.net/moovida/04-geographic-
scripting-in-udig-halfway-between-user-and-developer
GeoServer
• Web services
• Web Processing Services (WPS)
• Filter Functions (used in SLDs for styling your maps)
• Download groovy plugin from http://
ares.opengeo.org/geoserver/2.4.x/community-latest/
• Extract jars to geoserver/WEB-INF/lib
• http://www.slideshare.net/JaredErickson/scriptinggeoserver
As a library
Geoscript is just another jar
<repositories>!
<repository>!
<id>opengeo</id>!
<name>OpenGeo Maven Repository</name>!
<url>http://repo.opengeo.org</url>!
<snapshots>!
<enabled>true</enabled>!
</snapshots>!
</repository>!
</repositories>
<dependency>!
<groupId>org.geoscript</groupId>!
<artifactId>geoscript-groovy</artifactId>!
<version>1.2</version>!
</dependency>
Gradle - App
$ mkdir geo-gradle
$ cd geo-gradle/
$ touch build.gradle
$ vi build.gradle
$ mkdir -p src/main/groovy/org/jce/geo
$ touch src/main/groovy/org/jce/geo/App.groovy
$ vi src/main/groovy/org/jce/geo/App.groovy
$ gradle build