GeoScript - Spatial Capabilities for Scripting Languages

Justin Deoliveira
Justin DeoliveiraSoftware Developer at OpenGeo
GeoScript Spatial Capabilities for Scripting Languages Justin Deolivera, Tim Schaub, and Jared Erickson
Introduction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scripting Platform for JVM Languages ,[object Object],[object Object]
Groovy ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JavaScript ,[object Object],[object Object],[object Object],[object Object],[object Object]
Python ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Scala
On the shoulders of giants...
GeoScript Modules
Geometry ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Geometry >>>  from geoscript import geom >>>  geom.Point(30, 10) POINT(30 10)
Geometry >>>  import geoscript.geom.* >>>  line = new LineString([[111.0, -47], [123.0, -48], [110.0, -47]]) LINESTRING (111 -47, 123 -48, 110 -47)
Geometry js>  var poly = geom.Point([10, 30]).    >      buffer(5) js>  poly <Polygon [[[15, 30], [14.90...> js>  poly.area 78.03612880645133
Geometry - I/O >>>  from geoscript import geom >>>  point = geom.Point(30, 10) >>>  geom.writeKML(point) <kml:Point xmlns:kml=&quot;http://earth.google.com/kml/2.1&quot;>   <kml:coordinates>0.0,0.0</kml:coordinates> </kml:Point>
Geometry - I/O >>>  import geoscript.geom.Point >>>  import geoscript.geom.io.Gml2Writer >>>  p = new Point(111, -47) >>>  gml = new Gml2Writer() >>>  gml.write(p) <gml:Point>   <gml:coordinates>111.0,-47.0</gml:coordinates> </gml:Point>
Geometry - I/O js>  var geom = require(&quot;geoscript/geom&quot;); js>  var point = geom.Point([1, 2]) js>  point.json {&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[1,2]}
Geometry - Visualization >>>  from geoscript.render import plot >>> from geoscript import geom >>> poly = geom.Polygon([(35,10), (10,20), (15,40), (45,45), (35,10)], [(20,30), (35,35), (30,20), (20,30)]) >>>  plot(poly)
Geometry - Visualization js>  var geom = require(&quot;geoscript/geom&quot;) js>  require(&quot;geoscript/viewer&quot;).bind()   js>  var poly1 = geom.Point([0, 0]).buffer(1) js>  var poly2 = poly1.transform({dx: 0.5, dy: 0.5}) js>  poly1.difference(poly2) <Polygon [[[0.9095298326166407, -0.409529...>
Projection ,[object Object],[object Object],[object Object]
Projection js>  var proj = require(&quot;geoscript/proj&quot;); js>  var p = proj.Projection(&quot;epsg:4326&quot;); js>  p.wkt GEOGCS[&quot;WGS 84&quot;,     DATUM[&quot;World Geodetic System 1984&quot;,     ...
Projection >>> from geoscript import geom >>> from geoscript.proj import Projection >>> p = Projection('epsg:4326') >>>  p.transform((-111, 45.7), 'epsg:26912') (500000.0, 5060716.313515949) >>> g = geom.Point(0, 0).buffer(4) >>> g = reduce(lambda x,y:x.union(y),[geom.transform(g,dx=x,dy=y)        for x,y in [(3,0),(0,3),(-3,0),(0,-3)]]) >>>  p.transform(g, 'epsg:26912') >>>  p.transform(g, 'epsg:3005') Reprojection WGS 84 UTM Albers
Data Access ,[object Object],[object Object],[object Object],[object Object],[object Object]
Data Access - Workspace js>  var ws = require(&quot;geoscript/workspace&quot;);         js>  var dir = ws.Directory(&quot;data&quot;);    js>  dir            <Directory [&quot;states&quot;]> js>  var states = dir.get(&quot;states&quot;); js>  states <Layer name: states, count: 49>
Data Access - Workspace >>  from geoscript.workspace import PostGIS >>  pg = PostGIS('spearfish') >>  pg.layers() ['archsites', 'bugsites', ..., 'streams'] >>  l = pg['archsites']
Data Access - Workspace >>>  import geoscript.workspace.H2 >>>  import geoscript.geom.Point >>>  import geoscript.feature.Feature >>>  h2 = new H2(&quot;name&quot;, &quot;path&quot;) >>>  layer = h2.create(&quot;points&quot;, [      new Field(&quot;geom&quot;,&quot;Point&quot;),      new Field(&quot;name&quot;,&quot;String&quot;) ]) >>>  layer.add([new Point[1,1],&quot;one&quot;])
Data Access - Layers >>>  from geoscript.layer import Shapefile >>>  states = Shapefile('states.shp') >>>  states = states.reproject('epsg:3005')
Data Access - Layer Info >>>  import geoscript.layer.Shapefile >>>  shp = new Shapefile(&quot;states.shp&quot;) >>>  shp.count 49 >>>  shp.bounds (-124.73142200000001, 24.955967,-66.969849, 49.371735, EPSG:4326) >>>  shp.schema.fields.each {    fld -> println fld} the_geom: MultiPolygon(EPSG:4326) STATE_NAME: String STATE_FIPS: String SUB_REGION: String STATE_ABBR: String
Data Access - Layers js>  var ws = require(&quot;geoscript/workspace&quot;);        js>  var dir = ws.Directory(&quot;data&quot;);    js>  var states = dir.get(&quot;states&quot;); js>  states.query(&quot;STATE_ABBR like 'M%'&quot;).forEach(    >      function(feature) {    >          print(feature.get(&quot;STATE_NAME&quot;));    >      }    >  ) Maryland Missouri Mississippi ...
Styling and Rendering ,[object Object],[object Object],[object Object],[object Object]
Styling - Stroke >>>  from geoscript.style import Stroke >>>  Stroke('#000000', width=2) >>>  Stroke('black', width=2, dash=[5,5]) >>>  Stroke((0,0,0),width=2).hatch('vertline')
Styling - Fill >>>  import geoscript.style.Fill >>>  new Fill(&quot;gray&quot;) >>>  new Fill(&quot;gray&quot;, 0.5)) >>>  new Fill(&quot;gray&quot;).hatch(&quot;backslash&quot;) >>>  new Stroke(&quot;red&quot;,2) + new Fill(&quot;gray&quot;).hatch(&quot;times&quot;)
Styling - Shape and Icon js>  var style = require(&quot;geoscript/style&quot;); js>  style.Shape({name: &quot;star&quot;, fill: &quot;yellow&quot;}) <Shape name: 'star', size: 6> js>  style.Icon(&quot;rainy.svg&quot;) <Icon url: 'rainy.svg'>
Styling - Labels >>>  from geoscript.style import Label,Stroke,Fill,Shape >>>  font = 'bold 16px Arial' >>>   Shape() +  Label('name',font)       .point(displace=(20,0)) >>>   Stroke() +  Label('name',font)       .linear(offset=10) >>>   Fill() +  Label('name',font).halo('white',2)
Styling - Scale >>>  new Shape('#004d96', 5).range(3000)  + new Icon('school20.png').range(1500, 3000) + new Icon('school40.png').range(-1, 1500)
Styling - Theming >>> from geoscript.style Stroke, Fill, Label >>> style = Stroke() + Label('STATE_ABBR', 14, 'Serif') >>> style += Fill('#4DFF4D', 0.7)        .where('PERSONS < 2000000') >>> style += Fill('#FF4D4D', 0.7)       .where('PERSONS BETWEEN 2000000 AND 4000000') >>> style += Fill('#4D4DFF', 0.7)       .where('PERSONS > 4000000')
Demos
Voronoi Diagram Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Gradient  Example var Directory = require(&quot;geoscript/workspace&quot;).Directory; var {Fill, gradient} = require(&quot;geoscript/style&quot;); var Map = require(&quot;geoscript/map&quot;).Map; var states = Directory(&quot;data&quot;).get(&quot;states&quot;); states.style = gradient({      expression: &quot;PERSONS / LAND_KM&quot;,       values: [0, 200],       styles: [Fill(&quot;#000066&quot;), Fill(&quot;red&quot;)],      classes: 10,       method: &quot;exponential&quot; }).and(      Fill(&quot;red&quot;).where(&quot;PERSONS / LAND_KM > 200&quot;) ); var map = Map([states]); map.render({path: &quot;states.png&quot;});
Shapefile to PostGIS from geoscript.workspace import Directory, PostGIS shps = Directory('shapefiles') shps.layers() archsites = shps['archsites'] archsites.proj.id pg = PostGIS('demo') pg.layers() for layer in shps:    reprojected = shps[layer].reproject('epsg:4326')    pg.add(reprojected, name=layer) pg.layers() archsites = pg['archsites'] archsites.proj.id
Road Map ,[object Object],[object Object],[object Object],[object Object]
Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Thank you!
Centroids ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Shapefiles to PostGIS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
USGS Earth Quakes Read RSS Feed to a Shapefile
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Web Applications ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Graffiti Micro Web Framework
Geometry Web Services 
Geometry Web Services Open Layers function centroid() {     var features = vectorLayer.features;     if (features.length == 0) {        alert(&quot;Please add some features!&quot;);     } else {        OpenLayers.loadURL('centroid', {              geom: wktFormat.write(features)           },            this,            function(request) {              var wkt = request.responseText;              var features = wktFormat.read(wkt);              if (features) vectorLayer.addFeatures(features);           },            function() {              alert(&quot;Error calculating centroids!&quot;);           }        );     } }
WMS Server ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WMS Server... import geoscript.map.Map import geoscript.style.* import geoscript.layer.Shapefile import geoscript.geom.Bounds def file = new File(&quot;states.shp&quot;) def shp = new Shapefile(file) shp.style = new Fill(&quot;steelblue&quot;) + new Stroke(&quot;wheat&quot;, 0.1) def map = new Map(      width: 256,       height: 256,       layers: [shp],      proj: shp.proj,      fixAspectRatio: false ) def bbox = request.getParameter(&quot;BBOX&quot;).split(&quot;,&quot;) def bounds = new Bounds(bbox[0] as double, bbox[1] as double, bbox[2] as double, bbox[3] as double) map.bounds = bounds response.contentType = &quot;image/png&quot; map.render(response.outputStream) map.close()
Geometry Command line  ,[object Object],def cli = new CliBuilder(usage: 'geoscript-groovy geom_buffer.groovy -d') cli.d(longOpt: 'distance', 'buffer distance', args:1) cli.h(longOpt: 'help', 'Show usage information and quit') def opt = cli.parse(args) if(!opt) return if (opt.h || !opt.d) cli.usage() else println geoscript.geom.Geometry.fromWKT(System.in.text).buffer(opt.d as double).wkt def cli = new CliBuilder(usage: 'geoscript-groovy geom_envelope.groovy') cli.h(longOpt: 'help', 'Show usage information and quit') def opt = cli.parse(args) if(!opt) return if (opt.h) cli.usage() else println geoscript.geom.Geometry.fromWKT(System.in.text).bounds.geometry.wkt geom_buffer.groovy geom_envelope.groovy
1 of 52

Recommended

Scripting GeoServer with GeoScript by
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptJustin Deoliveira
3.9K views39 slides
The State of GeoServer by
The State of GeoServerThe State of GeoServer
The State of GeoServerJustin Deoliveira
2K views65 slides
Scripting GeoServer by
Scripting GeoServerScripting GeoServer
Scripting GeoServerJared Erickson
3.4K views29 slides
Rendering Maps in GeoScript by
Rendering Maps in GeoScriptRendering Maps in GeoScript
Rendering Maps in GeoScriptJared Erickson
1.2K views29 slides
Utilizing Powerful Extensions for Analytics and Operations by
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsNeo4j
378 views163 slides
3 u-mpb2u2na by
 3 u-mpb2u2na 3 u-mpb2u2na
3 u-mpb2u2najudith Steffan
133 views14 slides

More Related Content

What's hot

Taking Apache Camel For A Ride by
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce Snyder
1.5K views68 slides
Letswift19-clean-architecture by
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architectureJung Kim
1.6K views104 slides
RubyKaigi2015 making robots-with-mruby by
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyyamanekko
13K views103 slides
Map kit light by
Map kit lightMap kit light
Map kit lightCocoaHeads France
2.2K views100 slides
The Ring programming language version 1.5.3 book - Part 40 of 184 by
The Ring programming language version 1.5.3 book - Part 40 of 184The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184Mahmoud Samir Fayed
17 views10 slides
Minimizing Decision Fatigue to Improve Team Productivity by
Minimizing Decision Fatigue to Improve Team ProductivityMinimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team ProductivityDerek Lee Boire
1.9K views56 slides

What's hot(20)

Taking Apache Camel For A Ride by Bruce Snyder
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
Bruce Snyder1.5K views
Letswift19-clean-architecture by Jung Kim
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architecture
Jung Kim1.6K views
RubyKaigi2015 making robots-with-mruby by yamanekko
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mruby
yamanekko13K views
The Ring programming language version 1.5.3 book - Part 40 of 184 by Mahmoud Samir Fayed
The Ring programming language version 1.5.3 book - Part 40 of 184The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184
Minimizing Decision Fatigue to Improve Team Productivity by Derek Lee Boire
Minimizing Decision Fatigue to Improve Team ProductivityMinimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team Productivity
Derek Lee Boire1.9K views
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course by Sages
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash courseCodepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Sages925 views
Build Lightweight Web Module by Morgan Cheng
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
Morgan Cheng450 views
Relaxing With CouchDB by leinweber
Relaxing With CouchDBRelaxing With CouchDB
Relaxing With CouchDB
leinweber1.1K views
Protocol-Oriented Networking by Mostafa Amer
Protocol-Oriented NetworkingProtocol-Oriented Networking
Protocol-Oriented Networking
Mostafa Amer624 views
Wprowadzenie do technologi Big Data i Apache Hadoop by Sages
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache Hadoop
Sages1.7K views
JavaScript 2016 for C# Developers by Rick Beerendonk
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
Rick Beerendonk563 views
Reactive Access to MongoDB from Scala by Hermann Hueck
Reactive Access to MongoDB from ScalaReactive Access to MongoDB from Scala
Reactive Access to MongoDB from Scala
Hermann Hueck3.1K views

Similar to GeoScript - Spatial Capabilities for Scripting Languages

Html and i_phone_mobile-2 by
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2tonvanbart
610 views21 slides
Python And GIS - Beyond Modelbuilder And Pythonwin by
Python And GIS - Beyond Modelbuilder And PythonwinPython And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And PythonwinChad Cooper
648 views19 slides
Google maps by
Google mapsGoogle maps
Google mapsanupamasingh87
426 views32 slides
Google maps by
Google mapsGoogle maps
Google mapsanupamasingh87
702 views32 slides
Intro To PostGIS by
Intro To PostGISIntro To PostGIS
Intro To PostGISmleslie
35.6K views289 slides
Yahoo Query Language: Select * from Internet by
Yahoo Query Language: Select * from InternetYahoo Query Language: Select * from Internet
Yahoo Query Language: Select * from Internetdrgath
2.8K views26 slides

Similar to GeoScript - Spatial Capabilities for Scripting Languages(20)

Html and i_phone_mobile-2 by tonvanbart
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
tonvanbart610 views
Python And GIS - Beyond Modelbuilder And Pythonwin by Chad Cooper
Python And GIS - Beyond Modelbuilder And PythonwinPython And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And Pythonwin
Chad Cooper648 views
Intro To PostGIS by mleslie
Intro To PostGISIntro To PostGIS
Intro To PostGIS
mleslie35.6K views
Yahoo Query Language: Select * from Internet by drgath
Yahoo Query Language: Select * from InternetYahoo Query Language: Select * from Internet
Yahoo Query Language: Select * from Internet
drgath2.8K views
Beholding the giant pyramid of application development; why Ajax applications... by Javeline B.V.
Beholding the giant pyramid of application development; why Ajax applications...Beholding the giant pyramid of application development; why Ajax applications...
Beholding the giant pyramid of application development; why Ajax applications...
Javeline B.V.552 views
Designing and developing mobile web applications with Mockup, Sencha Touch an... by Matteo Collina
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Matteo Collina6.9K views
Google MAP API by Eric Lee
Google MAP APIGoogle MAP API
Google MAP API
Eric Lee1.1K views
Use of django at jolt online v3 by Jaime Buelta
Use of django at jolt online v3Use of django at jolt online v3
Use of django at jolt online v3
Jaime Buelta795 views
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG by Patrick Chanezon
JavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVGJavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
Patrick Chanezon1.6K views
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010 by Sergey Ilinsky
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Sergey Ilinsky1.5K views
Introduction To Groovy 2005 by Tugdual Grall
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
Tugdual Grall856 views
XML-Free Programming by Stephen Chin
XML-Free ProgrammingXML-Free Programming
XML-Free Programming
Stephen Chin1.9K views
How data rules the world: Telemetry in Battlefield Heroes by Electronic Arts / DICE
How data rules the world: Telemetry in Battlefield HeroesHow data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield Heroes
Groovy by Zen Urban
GroovyGroovy
Groovy
Zen Urban1.1K views
Introduction To PostGIS by mleslie
Introduction To PostGISIntroduction To PostGIS
Introduction To PostGIS
mleslie6.5K views

Recently uploaded

Voice Logger - Telephony Integration Solution at Aegis by
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
39 views1 slide
Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
14 views1 slide
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...Bernd Ruecker
37 views69 slides
Powerful Google developer tools for immediate impact! (2023-24) by
Powerful Google developer tools for immediate impact! (2023-24)Powerful Google developer tools for immediate impact! (2023-24)
Powerful Google developer tools for immediate impact! (2023-24)wesley chun
10 views38 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 slide
"Running students' code in isolation. The hard way", Yurii Holiuk by
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk Fwdays
11 views34 slides

Recently uploaded(20)

Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views
Powerful Google developer tools for immediate impact! (2023-24) by wesley chun
Powerful Google developer tools for immediate impact! (2023-24)Powerful Google developer tools for immediate impact! (2023-24)
Powerful Google developer tools for immediate impact! (2023-24)
wesley chun10 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays11 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson85 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely21 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive

GeoScript - Spatial Capabilities for Scripting Languages

  • 1. GeoScript Spatial Capabilities for Scripting Languages Justin Deolivera, Tim Schaub, and Jared Erickson
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. On the shoulders of giants...
  • 10.
  • 11. Geometry >>> from geoscript import geom >>> geom.Point(30, 10) POINT(30 10)
  • 12. Geometry >>>  import geoscript.geom.* >>> line = new LineString([[111.0, -47], [123.0, -48], [110.0, -47]]) LINESTRING (111 -47, 123 -48, 110 -47)
  • 13. Geometry js> var poly = geom.Point([10, 30]).   >     buffer(5) js> poly <Polygon [[[15, 30], [14.90...> js> poly.area 78.03612880645133
  • 14. Geometry - I/O >>>  from geoscript import geom >>>  point = geom.Point(30, 10) >>>  geom.writeKML(point) <kml:Point xmlns:kml=&quot;http://earth.google.com/kml/2.1&quot;>   <kml:coordinates>0.0,0.0</kml:coordinates> </kml:Point>
  • 15. Geometry - I/O >>> import geoscript.geom.Point >>> import geoscript.geom.io.Gml2Writer >>> p = new Point(111, -47) >>> gml = new Gml2Writer() >>> gml.write(p) <gml:Point>   <gml:coordinates>111.0,-47.0</gml:coordinates> </gml:Point>
  • 16. Geometry - I/O js> var geom = require(&quot;geoscript/geom&quot;); js> var point = geom.Point([1, 2]) js> point.json {&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[1,2]}
  • 17. Geometry - Visualization >>>  from geoscript.render import plot >>> from geoscript import geom >>> poly = geom.Polygon([(35,10), (10,20), (15,40), (45,45), (35,10)], [(20,30), (35,35), (30,20), (20,30)]) >>>  plot(poly)
  • 18. Geometry - Visualization js> var geom = require(&quot;geoscript/geom&quot;) js> require(&quot;geoscript/viewer&quot;).bind()   js> var poly1 = geom.Point([0, 0]).buffer(1) js> var poly2 = poly1.transform({dx: 0.5, dy: 0.5}) js> poly1.difference(poly2) <Polygon [[[0.9095298326166407, -0.409529...>
  • 19.
  • 20. Projection js> var proj = require(&quot;geoscript/proj&quot;); js> var p = proj.Projection(&quot;epsg:4326&quot;); js> p.wkt GEOGCS[&quot;WGS 84&quot;,    DATUM[&quot;World Geodetic System 1984&quot;,    ...
  • 21. Projection >>> from geoscript import geom >>> from geoscript.proj import Projection >>> p = Projection('epsg:4326') >>>  p.transform((-111, 45.7), 'epsg:26912') (500000.0, 5060716.313515949) >>> g = geom.Point(0, 0).buffer(4) >>> g = reduce(lambda x,y:x.union(y),[geom.transform(g,dx=x,dy=y)        for x,y in [(3,0),(0,3),(-3,0),(0,-3)]]) >>>  p.transform(g, 'epsg:26912') >>>  p.transform(g, 'epsg:3005') Reprojection WGS 84 UTM Albers
  • 22.
  • 23. Data Access - Workspace js> var ws = require(&quot;geoscript/workspace&quot;);        js> var dir = ws.Directory(&quot;data&quot;);    js> dir           <Directory [&quot;states&quot;]> js> var states = dir.get(&quot;states&quot;); js> states <Layer name: states, count: 49>
  • 24. Data Access - Workspace >>  from geoscript.workspace import PostGIS >>  pg = PostGIS('spearfish') >>  pg.layers() ['archsites', 'bugsites', ..., 'streams'] >> l = pg['archsites']
  • 25. Data Access - Workspace >>> import geoscript.workspace.H2 >>> import geoscript.geom.Point >>> import geoscript.feature.Feature >>> h2 = new H2(&quot;name&quot;, &quot;path&quot;) >>> layer = h2.create(&quot;points&quot;, [     new Field(&quot;geom&quot;,&quot;Point&quot;),     new Field(&quot;name&quot;,&quot;String&quot;) ]) >>> layer.add([new Point[1,1],&quot;one&quot;])
  • 26. Data Access - Layers >>> from geoscript.layer import Shapefile >>> states = Shapefile('states.shp') >>> states = states.reproject('epsg:3005')
  • 27. Data Access - Layer Info >>> import geoscript.layer.Shapefile >>> shp = new Shapefile(&quot;states.shp&quot;) >>> shp.count 49 >>> shp.bounds (-124.73142200000001, 24.955967,-66.969849, 49.371735, EPSG:4326) >>> shp.schema.fields.each {   fld -> println fld} the_geom: MultiPolygon(EPSG:4326) STATE_NAME: String STATE_FIPS: String SUB_REGION: String STATE_ABBR: String
  • 28. Data Access - Layers js>  var ws = require(&quot;geoscript/workspace&quot;);        js>  var dir = ws.Directory(&quot;data&quot;);    js>  var states = dir.get(&quot;states&quot;); js> states.query(&quot;STATE_ABBR like 'M%'&quot;).forEach(   >     function(feature) {   >         print(feature.get(&quot;STATE_NAME&quot;));   >     }   > ) Maryland Missouri Mississippi ...
  • 29.
  • 30. Styling - Stroke >>>  from geoscript.style import Stroke >>>  Stroke('#000000', width=2) >>>  Stroke('black', width=2, dash=[5,5]) >>>  Stroke((0,0,0),width=2).hatch('vertline')
  • 31. Styling - Fill >>> import geoscript.style.Fill >>>  new Fill(&quot;gray&quot;) >>>  new Fill(&quot;gray&quot;, 0.5)) >>>  new Fill(&quot;gray&quot;).hatch(&quot;backslash&quot;) >>>  new Stroke(&quot;red&quot;,2) + new Fill(&quot;gray&quot;).hatch(&quot;times&quot;)
  • 32. Styling - Shape and Icon js> var style = require(&quot;geoscript/style&quot;); js> style.Shape({name: &quot;star&quot;, fill: &quot;yellow&quot;}) <Shape name: 'star', size: 6> js> style.Icon(&quot;rainy.svg&quot;) <Icon url: 'rainy.svg'>
  • 33. Styling - Labels >>>  from geoscript.style import Label,Stroke,Fill,Shape >>>  font = 'bold 16px Arial' >>> Shape() + Label('name',font)       .point(displace=(20,0)) >>> Stroke() + Label('name',font)       .linear(offset=10) >>>   Fill() + Label('name',font).halo('white',2)
  • 34. Styling - Scale >>> new Shape('#004d96', 5).range(3000)  + new Icon('school20.png').range(1500, 3000) + new Icon('school40.png').range(-1, 1500)
  • 35. Styling - Theming >>> from geoscript.style Stroke, Fill, Label >>> style = Stroke() + Label('STATE_ABBR', 14, 'Serif') >>> style += Fill('#4DFF4D', 0.7)       .where('PERSONS < 2000000') >>> style += Fill('#FF4D4D', 0.7)       .where('PERSONS BETWEEN 2000000 AND 4000000') >>> style += Fill('#4D4DFF', 0.7)       .where('PERSONS > 4000000')
  • 36. Demos
  • 37.
  • 38. Gradient  Example var Directory = require(&quot;geoscript/workspace&quot;).Directory; var {Fill, gradient} = require(&quot;geoscript/style&quot;); var Map = require(&quot;geoscript/map&quot;).Map; var states = Directory(&quot;data&quot;).get(&quot;states&quot;); states.style = gradient({     expression: &quot;PERSONS / LAND_KM&quot;,      values: [0, 200],      styles: [Fill(&quot;#000066&quot;), Fill(&quot;red&quot;)],     classes: 10,      method: &quot;exponential&quot; }).and(     Fill(&quot;red&quot;).where(&quot;PERSONS / LAND_KM > 200&quot;) ); var map = Map([states]); map.render({path: &quot;states.png&quot;});
  • 39. Shapefile to PostGIS from geoscript.workspace import Directory, PostGIS shps = Directory('shapefiles') shps.layers() archsites = shps['archsites'] archsites.proj.id pg = PostGIS('demo') pg.layers() for layer in shps:   reprojected = shps[layer].reproject('epsg:4326')   pg.add(reprojected, name=layer) pg.layers() archsites = pg['archsites'] archsites.proj.id
  • 40.
  • 41.
  • 43.
  • 44.
  • 45. USGS Earth Quakes Read RSS Feed to a Shapefile
  • 46.
  • 47.
  • 49. Geometry Web Services Open Layers function centroid() {     var features = vectorLayer.features;     if (features.length == 0) {       alert(&quot;Please add some features!&quot;);     } else {       OpenLayers.loadURL('centroid', {             geom: wktFormat.write(features)           },            this,            function(request) {             var wkt = request.responseText;             var features = wktFormat.read(wkt);             if (features) vectorLayer.addFeatures(features);           },            function() {             alert(&quot;Error calculating centroids!&quot;);           }       );     } }
  • 50.
  • 51. WMS Server... import geoscript.map.Map import geoscript.style.* import geoscript.layer.Shapefile import geoscript.geom.Bounds def file = new File(&quot;states.shp&quot;) def shp = new Shapefile(file) shp.style = new Fill(&quot;steelblue&quot;) + new Stroke(&quot;wheat&quot;, 0.1) def map = new Map(     width: 256,      height: 256,      layers: [shp],     proj: shp.proj,     fixAspectRatio: false ) def bbox = request.getParameter(&quot;BBOX&quot;).split(&quot;,&quot;) def bounds = new Bounds(bbox[0] as double, bbox[1] as double, bbox[2] as double, bbox[3] as double) map.bounds = bounds response.contentType = &quot;image/png&quot; map.render(response.outputStream) map.close()
  • 52.