SlideShare a Scribd company logo
Using GeoScript
Groovy
Jared Erickson	

CUGOS February 2014
What is GeoScript?
• Geospatial Swiss Army Knife	

• One scripting API Many Languages
What is Groovy?
• Yes, there is a language called Groovy 	

• Dynamic JVM Language	

• Strong Java Integration	

• Closures, MetaProgramming, Scripting
Uses
• Scripts	

• Shell	

• Console	

• GeoServer	

• uDig	

• Apps (GeoScript as a Library)
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/
Command line tools
geoscript-groovy = run scripts	

geoscript-groovysh = interactive shell	

geoscript-groovyConsole = mini ide	

!
Inline Scripts 	

(geoscript-groovy)

geoscript-groovy -e "println new
geoscript.layer.Shapefile('states.shp').toJSONString()" |
mapfart	

!

geoscript-groovy -e "println new
geoscript.layer.Shapefile('states.shp').bounds.geometry"	

!

geoscript-groovy -e "println new
geoscript.layer.Shapefile('states.shp').count"
Inline Scripts	

(geoscript-groovy)

geoscript-groovy -e "geoscript.render.Draw.draw(new
geoscript.layer.Shapefile('states.shp'), out: 'image.png')"	

!

geoscript-groovy -e "new
geoscript.layer.Shapefile('states.shp').eachFeature{ println
it.geom.centroid}" | geom combine | geom buffer -d 1.5	

!

echo "POINT (1 1)" | geom buffer -d 10 | geoscriptgroovy -e "println
geoscript.geom.Geometry.fromWKT(System.in.text).kml"
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)

web/buffer.groovy
1
2
3
4
5

import geoscript.geom.*!
!
def geom = Geometry.fromWKT(request.getParameter("geom"))!
def distance = request.getParameter("d") as double!
println(geom.buffer(distance).wkt)

web/draw.groovy
1
2
3
4
5
6
7

import geoscript.geom.*!
import geoscript.viewer.Viewer!
!
def geom = Geometry.fromWKT(request.getParameter("geom"))!
def image = Viewer.drawToImage(geom, size: [400, 400])!
response.contentType = "image/png"!
javax.imageio.ImageIO.write(image, "png", response.outputStream)
Scripts	

(groovy)

1
2
3
4
5
6
7

@GrabResolver(name="opengeo", root="http://repo.opengeo.org")!
@Grab("org.geoscript:geoscript-groovy:1.1")!
import geoscript.geom.Point!
!
p = new Point(1,1)!
println p.geoJSON!

• Use GeoScript without installing GeoScript	

• Just need Java and Groovy	

• @GrabResolver and @Grab can download
dependencies
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)
Shell	


(geoscript-groovysh)
groovy:000> states.schema.fields	

===> [the_geom: MultiPolygon(EPSG:4326), STATE_NAME: String, STATE_FIPS: String,
SUB_REGION: String, STATE_ABBR: String, LAND_KM: Double, WATER_KM: Double, PERSONS:
Double, FAMILIES: Double, HOUSHOLD: Double, MALE: Double, FEMALE: Double, WORKERS:
Double, DRVALONE: Double, CARPOOL: Double, PUBTRANS: Double, EMPLOYED: Double,
UNEMPLOY: Double, SERVICE: Double, MANUAL: Double, P_MALE: Double, P_FEMALE: Double,
SAMP_POP: Double]	

groovy:000> state_centroids = states.transform("state_centroids", [the_geom:
"centroid(the_geom)", name: "STATE_NAME", abbreviation: "STATE_ABBR"])	

===> state_centroids	

groovy:000> state_centroids.count	

===> 49	

groovy:000> postgis	

===> geoscript.workspace.PostGIS@7840df80	

groovy:000> postgis.add(state_centroids)	

===> state_centroids	

groovy:000> postgis.names	

===> [state_centroids, states]	

groovy:000> postgis["state_centroids"].schema	

===> state_centroids the_geom: Point(EPSG:4326), name: String, abbreviation: String
Shell	


(geoscript-groovysh)

• Good for trying things out	

• Interact and explore all things geospatial
Console	


(geoscript-groovyConsole)
Console 	


(geoscript-groovyConsole)
Console 	


geoscript-groovyConsole
Console
• Good for longer scripts (but not too long)	

• Excellent preview (View -> Visualize Script
Results)	


• Use it when rendering images, maps,
geometries
uDig
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
GeoServer
$DATA_DIR/scripts/wps/buffer.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

import geoscript.geom.Geometry!
!
title = 'Buffer'!
description = 'Buffers a geometry'!
!
inputs = [!
geom: [name: 'geom', title: 'The geometry to buffer', type: Geometry.class],!
distance: [name: 'distance', title: 'The buffer distance', type: Double.class]!
]!
!
outputs = [!
result: [name: 'result', title: 'The buffered geometry', type: Geometry.class]!
]!
!
def run(input) {!
[result: input.geom.buffer(input.distance as double)]!
}!
GeoServer
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
Gradle - build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

apply plugin: "groovy"!
apply plugin: "application"!
!
version = 0.1!
mainClassName = "org.jce.geo.App"!
!
repositories {!
maven {!
url "http://repo.opengeo.org"!
}!
maven {!
url "http://download.osgeo.org/webdav/geotools/"!
}!
mavenCentral()!
}!
!
dependencies {!
compile "org.codehaus.groovy:groovy-all:2.1.9"!
compile "org.geoscript:geoscript-groovy:1.2"!
}
Gradle - Code
src/main/groovy/org/jce/geo/App.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14

package org.jce.geo!
!
import geoscript.geom.Geometry!
import geoscript.proj.Projection!
!
class App {!
static void main(String[] args) {!
Geometry geom = Geometry.fromString(args[0])!
Projection fromProj = new Projection(args[1])!
Projection toProj = new Projection(args[2])!
Geometry transformedGeom = fromProj.transform(geom, toProj)!
println transformedGeom.wkt!
}!
}
Using GeoScript Groovy
Functionality

• Geometry	

• Projection	

• Layer	

• Raster	

• Style	

• Render	


Usages

• Scripts	

• Shell	

• Console	

• GeoServer	

• uDig	

• Apps
Thank you!

More Related Content

What's hot

[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
ZeroTurnaround
 
Rest, sockets em golang
Rest, sockets em golangRest, sockets em golang
Rest, sockets em golang
jefferson Otoni Lima
 
Continuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin StachniukContinuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin Stachniuk
MarcinStachniuk
 
Devfest 2021' - Artifact Registry Introduction (Taipei)
Devfest 2021' - Artifact Registry Introduction (Taipei)Devfest 2021' - Artifact Registry Introduction (Taipei)
Devfest 2021' - Artifact Registry Introduction (Taipei)
KAI CHU CHUNG
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Fabian Jakobs
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and docker
Ortus Solutions, Corp
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Luciano Mammino
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
Ting-Li Chou
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
Tobias Oetiker
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
Corneil du Plessis
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
Pagepro
 
Openshift operator insight
Openshift operator insightOpenshift operator insight
Openshift operator insight
Ryan ZhangCheng
 
以 Ktor 快速打造 Web 應用
以 Ktor 快速打造 Web 應用以 Ktor 快速打造 Web 應用
以 Ktor 快速打造 Web 應用
Shengyou Fan
 
Paris container day june17
Paris container day   june17Paris container day   june17
Paris container day june17
Paris Container Day
 
Web2.0 with jQuery in English
Web2.0 with jQuery in EnglishWeb2.0 with jQuery in English
Web2.0 with jQuery in English
Lau Bech Lauritzen
 
Google Web Toolkitのすすめ
Google Web ToolkitのすすめGoogle Web Toolkitのすすめ
Google Web ToolkitのすすめKaisei Hamamoto
 
Meetup - retour sur la DrupalCon Dublin 2016
Meetup - retour sur la DrupalCon Dublin 2016Meetup - retour sur la DrupalCon Dublin 2016
Meetup - retour sur la DrupalCon Dublin 2016
Yann Jajkiewicz
 

What's hot (19)

Tp web
Tp webTp web
Tp web
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
 
Rest, sockets em golang
Rest, sockets em golangRest, sockets em golang
Rest, sockets em golang
 
Continuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin StachniukContinuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin Stachniuk
 
Devfest 2021' - Artifact Registry Introduction (Taipei)
Devfest 2021' - Artifact Registry Introduction (Taipei)Devfest 2021' - Artifact Registry Introduction (Taipei)
Devfest 2021' - Artifact Registry Introduction (Taipei)
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and docker
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
 
Openshift operator insight
Openshift operator insightOpenshift operator insight
Openshift operator insight
 
以 Ktor 快速打造 Web 應用
以 Ktor 快速打造 Web 應用以 Ktor 快速打造 Web 應用
以 Ktor 快速打造 Web 應用
 
Paris container day june17
Paris container day   june17Paris container day   june17
Paris container day june17
 
Web2.0 with jQuery in English
Web2.0 with jQuery in EnglishWeb2.0 with jQuery in English
Web2.0 with jQuery in English
 
Google Web Toolkitのすすめ
Google Web ToolkitのすすめGoogle Web Toolkitのすすめ
Google Web Toolkitのすすめ
 
Meetup - retour sur la DrupalCon Dublin 2016
Meetup - retour sur la DrupalCon Dublin 2016Meetup - retour sur la DrupalCon Dublin 2016
Meetup - retour sur la DrupalCon Dublin 2016
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 

Similar to Using Geoscript Groovy

Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
Guillaume Laforge
 
Saving Money with Open Source GIS
Saving Money with Open Source GISSaving Money with Open Source GIS
Saving Money with Open Source GIS
bryanluman
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
Jussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
Jussi Pohjolainen
 
GIS User to Web-GIS Developer Journey
GIS User to Web-GIS Developer JourneyGIS User to Web-GIS Developer Journey
GIS User to Web-GIS Developer Journey
Tek Kshetri
 
React nativebeginner1
React nativebeginner1React nativebeginner1
React nativebeginner1
Oswald Campesato
 
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Ranel Padon
 
New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011philogb
 
GAE_20100112
GAE_20100112GAE_20100112
GAE_20100112
Kosuke Matsuda
 
DevQuiz 2011 の模範解答 Android編
DevQuiz 2011 の模範解答 Android編DevQuiz 2011 の模範解答 Android編
DevQuiz 2011 の模範解答 Android編Makoto Yamazaki
 
Device系APIの全体図
Device系APIの全体図Device系APIの全体図
Device系APIの全体図
Kensaku Komatsu
 
Play Framework on Google App Engine
Play Framework on Google App EnginePlay Framework on Google App Engine
Play Framework on Google App Engine
Fred Lin
 
Geo script opengeo spring 2013
Geo script opengeo spring 2013Geo script opengeo spring 2013
Geo script opengeo spring 2013Ilya Rosenfeld
 
JavaScript on the Desktop
JavaScript on the DesktopJavaScript on the Desktop
JavaScript on the Desktop
Domenic Denicola
 
NLUUG Spring 2012 - OpenShift Primer
NLUUG Spring 2012 - OpenShift PrimerNLUUG Spring 2012 - OpenShift Primer
NLUUG Spring 2012 - OpenShift Primer
Eric D. Schabell
 
Grooscript gr8conf 2015
Grooscript gr8conf 2015Grooscript gr8conf 2015
Grooscript gr8conf 2015
Jorge Franco Leza
 
OpenShift State of the Union, brought to you by JBoss
OpenShift State of the Union, brought to you by JBossOpenShift State of the Union, brought to you by JBoss
OpenShift State of the Union, brought to you by JBoss
Eric D. Schabell
 
PyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopPyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopJachym Cepicky
 

Similar to Using Geoscript Groovy (20)

Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Saving Money with Open Source GIS
Saving Money with Open Source GISSaving Money with Open Source GIS
Saving Money with Open Source GIS
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
GIS User to Web-GIS Developer Journey
GIS User to Web-GIS Developer JourneyGIS User to Web-GIS Developer Journey
GIS User to Web-GIS Developer Journey
 
Mobile native-hacks
Mobile native-hacksMobile native-hacks
Mobile native-hacks
 
React nativebeginner1
React nativebeginner1React nativebeginner1
React nativebeginner1
 
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)
 
GIS_Day_2016
GIS_Day_2016GIS_Day_2016
GIS_Day_2016
 
New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011
 
GAE_20100112
GAE_20100112GAE_20100112
GAE_20100112
 
DevQuiz 2011 の模範解答 Android編
DevQuiz 2011 の模範解答 Android編DevQuiz 2011 の模範解答 Android編
DevQuiz 2011 の模範解答 Android編
 
Device系APIの全体図
Device系APIの全体図Device系APIの全体図
Device系APIの全体図
 
Play Framework on Google App Engine
Play Framework on Google App EnginePlay Framework on Google App Engine
Play Framework on Google App Engine
 
Geo script opengeo spring 2013
Geo script opengeo spring 2013Geo script opengeo spring 2013
Geo script opengeo spring 2013
 
JavaScript on the Desktop
JavaScript on the DesktopJavaScript on the Desktop
JavaScript on the Desktop
 
NLUUG Spring 2012 - OpenShift Primer
NLUUG Spring 2012 - OpenShift PrimerNLUUG Spring 2012 - OpenShift Primer
NLUUG Spring 2012 - OpenShift Primer
 
Grooscript gr8conf 2015
Grooscript gr8conf 2015Grooscript gr8conf 2015
Grooscript gr8conf 2015
 
OpenShift State of the Union, brought to you by JBoss
OpenShift State of the Union, brought to you by JBossOpenShift State of the Union, brought to you by JBoss
OpenShift State of the Union, brought to you by JBoss
 
PyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopPyWPS at COST WPS Workshop
PyWPS at COST WPS Workshop
 

Recently uploaded

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 

Using Geoscript Groovy

  • 2. What is GeoScript? • Geospatial Swiss Army Knife • One scripting API Many Languages
  • 3. What is Groovy? • Yes, there is a language called Groovy • Dynamic JVM Language • Strong Java Integration • Closures, MetaProgramming, Scripting
  • 4. Uses • Scripts • Shell • Console • GeoServer • uDig • Apps (GeoScript as a Library)
  • 5. 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
  • 6. How do I learn it? http://geoscript.org http://geoscript.org/groovy/api/
  • 7. Command line tools geoscript-groovy = run scripts geoscript-groovysh = interactive shell geoscript-groovyConsole = mini ide !
  • 8. Inline Scripts (geoscript-groovy) geoscript-groovy -e "println new geoscript.layer.Shapefile('states.shp').toJSONString()" | mapfart ! geoscript-groovy -e "println new geoscript.layer.Shapefile('states.shp').bounds.geometry" ! geoscript-groovy -e "println new geoscript.layer.Shapefile('states.shp').count"
  • 9. Inline Scripts (geoscript-groovy) geoscript-groovy -e "geoscript.render.Draw.draw(new geoscript.layer.Shapefile('states.shp'), out: 'image.png')" ! geoscript-groovy -e "new geoscript.layer.Shapefile('states.shp').eachFeature{ println it.geom.centroid}" | geom combine | geom buffer -d 1.5 ! echo "POINT (1 1)" | geom buffer -d 10 | geoscriptgroovy -e "println geoscript.geom.Geometry.fromWKT(System.in.text).kml"
  • 10. 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)
  • 11. 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()
  • 12. Scripts (geoscript-groovy) web/buffer.groovy 1 2 3 4 5 import geoscript.geom.*! ! def geom = Geometry.fromWKT(request.getParameter("geom"))! def distance = request.getParameter("d") as double! println(geom.buffer(distance).wkt) web/draw.groovy 1 2 3 4 5 6 7 import geoscript.geom.*! import geoscript.viewer.Viewer! ! def geom = Geometry.fromWKT(request.getParameter("geom"))! def image = Viewer.drawToImage(geom, size: [400, 400])! response.contentType = "image/png"! javax.imageio.ImageIO.write(image, "png", response.outputStream)
  • 13. Scripts (groovy) 1 2 3 4 5 6 7 @GrabResolver(name="opengeo", root="http://repo.opengeo.org")! @Grab("org.geoscript:geoscript-groovy:1.1")! import geoscript.geom.Point! ! p = new Point(1,1)! println p.geoJSON! • Use GeoScript without installing GeoScript • Just need Java and Groovy • @GrabResolver and @Grab can download dependencies
  • 14. 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
  • 15. 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)
  • 16. Shell (geoscript-groovysh) groovy:000> states.schema.fields ===> [the_geom: MultiPolygon(EPSG:4326), STATE_NAME: String, STATE_FIPS: String, SUB_REGION: String, STATE_ABBR: String, LAND_KM: Double, WATER_KM: Double, PERSONS: Double, FAMILIES: Double, HOUSHOLD: Double, MALE: Double, FEMALE: Double, WORKERS: Double, DRVALONE: Double, CARPOOL: Double, PUBTRANS: Double, EMPLOYED: Double, UNEMPLOY: Double, SERVICE: Double, MANUAL: Double, P_MALE: Double, P_FEMALE: Double, SAMP_POP: Double] groovy:000> state_centroids = states.transform("state_centroids", [the_geom: "centroid(the_geom)", name: "STATE_NAME", abbreviation: "STATE_ABBR"]) ===> state_centroids groovy:000> state_centroids.count ===> 49 groovy:000> postgis ===> geoscript.workspace.PostGIS@7840df80 groovy:000> postgis.add(state_centroids) ===> state_centroids groovy:000> postgis.names ===> [state_centroids, states] groovy:000> postgis["state_centroids"].schema ===> state_centroids the_geom: Point(EPSG:4326), name: String, abbreviation: String
  • 17. Shell (geoscript-groovysh) • Good for trying things out • Interact and explore all things geospatial
  • 21. Console • Good for longer scripts (but not too long) • Excellent preview (View -> Visualize Script Results) • Use it when rendering images, maps, geometries
  • 22. uDig
  • 23. 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
  • 24. 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
  • 25. GeoServer $DATA_DIR/scripts/wps/buffer.groovy 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import geoscript.geom.Geometry! ! title = 'Buffer'! description = 'Buffers a geometry'! ! inputs = [! geom: [name: 'geom', title: 'The geometry to buffer', type: Geometry.class],! distance: [name: 'distance', title: 'The buffer distance', type: Double.class]! ]! ! outputs = [! result: [name: 'result', title: 'The buffered geometry', type: Geometry.class]! ]! ! def run(input) {! [result: input.geom.buffer(input.distance as double)]! }!
  • 27. 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>
  • 28. 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
  • 29. Gradle - build.gradle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 apply plugin: "groovy"! apply plugin: "application"! ! version = 0.1! mainClassName = "org.jce.geo.App"! ! repositories {! maven {! url "http://repo.opengeo.org"! }! maven {! url "http://download.osgeo.org/webdav/geotools/"! }! mavenCentral()! }! ! dependencies {! compile "org.codehaus.groovy:groovy-all:2.1.9"! compile "org.geoscript:geoscript-groovy:1.2"! }
  • 30. Gradle - Code src/main/groovy/org/jce/geo/App.groovy 1 2 3 4 5 6 7 8 9 10 11 12 13 14 package org.jce.geo! ! import geoscript.geom.Geometry! import geoscript.proj.Projection! ! class App {! static void main(String[] args) {! Geometry geom = Geometry.fromString(args[0])! Projection fromProj = new Projection(args[1])! Projection toProj = new Projection(args[2])! Geometry transformedGeom = fromProj.transform(geom, toProj)! println transformedGeom.wkt! }! }
  • 31. Using GeoScript Groovy Functionality • Geometry • Projection • Layer • Raster • Style • Render Usages • Scripts • Shell • Console • GeoServer • uDig • Apps