-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
686 lines (605 loc) · 20.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GeoScript - The GeoSpatial Swiss Army Knife</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/simple.css" id="theme">
<link rel="stylesheet" href="css/style.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<header><a href="http://geoscript.org">http://geoscript.org</a></header>
<div class="slides">
<section>
<h1>GeoScript</h1>
<h3>The GeoSpatial Swiss Army Knife</h3>
<p>
<small>Jared Erickson & Justin Deoliveira</small>
</p>
</section>
<section>
<section>
<h2>What is GeoScript?</h2>
<p>Spatial capabilities for scripting languages on the JVM.</p>
<ul>
<li class="fragment">Groovy, Python, Javascript, Scala, Ruby</li>
<li class="fragment">Similar API across languages</li>
<li class="fragment">Convenience for JTS and GeoTools</li>
</ul>
</section>
</section>
<section>
<section>
<h2>GeoScript Modules</h2>
<img src="img/modules.png"></img>
</section>
</section>
<section>
<section>
<h2>Buffer a Point</h2>
<p class="text-right">Java</p>
<pre>
<code data-trim contenteditable class="java">
GeometryFactory geometryFactory = new GeometryFactory();
Point point = geometryFactory.createPoint(new Coordinate(-122.478899, 47.268195));
point.buffer(10);
</code>
</pre>
</section>
<section>
<h2>Buffer a Point</h2>
<p class="text-right">Groovy</p>
<pre>
<code data-trim contenteditable class="groovy">
new Point(-122.478899, 47.268195).buffer(10)
</code>
</pre>
<p class="text-right">Python</p>
<pre>
<code data-trim contenteditable class="python">
Point(-122.478899, 47.268195).buffer(10)
</code>
</pre>
</section>
</section>
<section>
<section>
<h2>Render a Map</h2>
<p class="text-right">Java</p>
<pre>
<code data-trim contenteditable class="java">
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
SLDParser parser = new SLDParser(styleFactory, new File("states.sld"));
Style style = parser.readXML()[0];
ShapefileDataStore shapefile = new ShapefileDataStore(new File("states.shp").toURI().oURL());
FeatureSource<SimpleFeatureType, SimpleFeature> features =
shapefile.getFeatureSource(shapefile.getTypeNames()[0]);
MapContext context = new DefaultMapContext(new MapLayer[]{
new DefaultMapLayer(features, style)
});
BufferedImage image = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();
Rectangle screenArea = new Rectangle(0, 0, 300, 300);
ReferencedEnvelope mapArea = features.getBounds();
StreamingRenderer renderer = new StreamingRenderer();
renderer.setContext(context);
renderer.paint(graphics, screenArea, mapArea);
ImageIO.write(image, "png", new File("states.png"));
</code>
</pre>
</section>
<section>
<h2>Render a Map</h2>
<p class="text-right">Groovy</p>
<pre>
<code data-trim contenteditable class="groovy">
Layer layer = new Shapefile("states.shp")
layer.style = new SLDReader().read(new File("states.sld"))
Map map = new Map(layers: [layer], width: 300, height: 300)
map.render(new File("states.png"))
</code>
</pre>
</section>
</section>
<section>
<section>
<h2>Load PostGIS Features</h2>
<p class="text-right">Java</p>
<pre>
<code data-trim contenteditable class="java">
Map<String, Object> params = new HashMap<String, Object>();
params.put("dbtype", "postgis");
params.put("database", "usa");
params.put("schema", "public");
params.put("host", "localhost");
params.put("port", "5432");
params.put("user", "bob");
DataStore dataStore = DataStoreFinder.getDataStore(params);
try {
SimpleFeatureSource featureSource = dataStore.getFeatureSource("states");
SimpleFeatureCollection featureCollection = featureSource.getFeatures();
SimpleFeatureIterator it = featureCollection.features();
try {
while(it.hasNext()) {
SimpleFeature f = it.next();
System.out.println(f.getAttribute("STATE_NAME") + " at " + ((Geometry)f.DefaultGeometry()).getCentroid().toText());
}
} finally {
it.close();
}
} finally {
dataStore.dispose();
}
</code>
</pre>
</section>
<section>
<h2>Load PostGIS Features</h2>
<p class="text-right">Python</p>
<pre>
<code data-trim contenteditable class="python">
PostGIS db = new PostGIS('usa', user: 'bob')
for f in db['states'].features():
print '%s at %s' % (f['STATE_NAME'], f.geom.centroid)
</code>
</pre>
</section>
</section>
<section>
<section>
<h2>Create a Shapefile</h2>
<p class="text-right">Java</p>
<pre>
<code data-trim contenteditable class="java">
SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
featureTypeBuilder.setName("points");
featureTypeBuilder.setSRS("EPSG:4326");
featureTypeBuilder.add("the_geom", Point);
featureTypeBuilder.add("id", Integer);
featureTypeBuilder.add("name", String);
SimpleFeatureType featureType = featureTypeBuilder.buildFeatureType();
File file = new File("points.shp");
Map<String,Object> params = new HashMap<String, Object>();
params.put("url", DataUtilities.fileToURL(file));
DataStore dataStore = DataStoreFinder.getDataStore(params);
dataStore.createSchema(featureType);
SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.FeatureSource("points");
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
GeometryFactory geometryFactory = new GeometryFactory();
FeatureCollection features = new DefaultFeatureCollection(null, featureType)
featureBuilder.add(geometryFactory.createPoint(new Coordinate(1, 1)));
featureBuilder.add(1);
featureBuilder.add("one");
features.add(featureBuilder.buildFeature(null));
featureBuilder.add(geometryFactory.createPoint(new Coordinate(2, 2)));
featureBuilder.add(2);
featureBuilder.add("two");
features.add(featureBuilder.buildFeature(null));
featureStore.addFeatures(features);
dataStore.dispose();
</code>
</pre>
</section>
<section>
<h2>Create a Shapefile</h2>
<p class="text-right">JavaScript</p>
<pre>
<code data-trim contenteditable class="javascript">
var dir = new Directory('.');
var shp = dir.add(new Layer({
name: 'points',
fields: [{
name: 'geom', type: 'Point'
}, {
name: 'id', type: 'Integer'
}, {
name: 'name', type: 'String'
}]
});
shp.add([new Point([1,1], 1, 'one')]);
shp.add([new Point([2,2], 2, 'two')]);
</code>
</pre>
</section>
</section>
<section>
<section>
<h2>What else can I do with GeoScript?</h2>
</section>
<section>
<p>Read, write, and translate spatial formats</p>
<pre>
<code data-trim contenteditable class="groovy">
import geoscript.workspace.*
import geoscript.layer.Layer
File dir = new File("shp")
PostGIS postgis = new PostGIS("naturalearth")
Directory directory = new Directory(dir)
directory.layers.each { Layer layer ->
postgis.add(layer)
}
</code>
</pre>
</section>
<section>
<p>Encode and decode exchange formats like GeoJSON, GML, WKT, and WKB</p>
<pre>
<code data-trim contenteditable class="python">
from geoscript.geom import readJSON, writeGML, readWKT, writeWKB
writeGML(readJSON("""{"type":"Point", "coordinates":[1,2]}"""))
writeWKB(readWKT("POINT (1 2)"))
</code>
</pre>
</section>
<section>
<p>Analyze data distribution</p>
<pre>
<code data-trim contenteditable class="python">
from geoscript.layer import GeoTIFF
dem = GeoTIFF('dem.tif')
h = dem.histogram()
data = zip(map(lambda (x,y): y, h.bins()), h.counts())
bar.xy(data, xlabel='Elevation').show()
</code>
</pre>
</section>
<section>
<p>Analyze data distribution</p>
<img src="img/histo.png"></img>
</section>
<section>
<p>Process and transform data on the fly</p>
<pre>
<code data-trim contenteditable class="javascript">
var proj = require('geoscript/proj')
var Directory = require('geoscript/workspace').Directory
var Layer = require('geoscript/layer').Layer
var shp = new Directory('.').get('states.shp')
var points = new Layer({
name: 'Points',
fields: [{
name: 'geom', type: 'Point'
}]
});
shp.features.forEach(function(f) {
points.add({
name: proj.transform(f.get('geom').centroid), "epsg:4326", "epsg:26912"
});
});
</code>
</pre>
</section>
<section>
<p>Generate styles for rendering maps</p>
<pre>
<code data-trim contenteditable class="python">
from geoscript.style import *
from geoscript.render import *
from geoscript.layer import Shapefile
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')
style += Stroke(width=0.2) + Label('STATE_ABBR', 'Times New Roman 14px')
draw(Shapefile('states.shp'), style)
</code>
</pre>
</section>
<section>
<p>Generate styles for rendering maps</p>
<img src="img/states.png"></img>
</section>
<section>
<p>Crop Raster with a Geometry</p>
<pre>
<code data-trim contenteditable class="groovy">
import geoscript.layer.*
import geoscript.geom.Point
import geoscript.proj.Projection
def tif = new GeoTIFF(new File("raster.tif"))
def raster = tif.read(new Projection("EPSG:4326"))
def geom = new Point(50,50).buffer(20)
def cropped = raster.crop(geom)
new GeoTIFF(new File("raster_circle_cropped.tif")).write(cropped)
</code>
</pre>
</section>
<section>
<p>Crop Raster with a Geometry</p>
<img src="img/raster_cropped.png"/>
</section>
</section>
<section>
<section>
<h2>How can I use GeoScript?</h2>
</section>
<section>
<h2>Read Eval Print Loop (REPL)</h2>
<img src="img/repl.png"/>
</section>
<section>
<h2>GeoServer WPS</h2>
</section>
<section>
<img src="img/geoserver-script1.png"></img>
</section>
<section>
<img src="img/geoserver-script2.png"></img>
</section>
<section>
<h2>uDig Spatial Toolbox</h2>
</section>
<section>
<img src="img/udig.png"/>
</section>
<section>
<h2>As a Library</h2>
</section>
<section>
<div style="text-align: right;">
<img src="img/maven-logo.png"></img>
</div>
<pre>
<code data-trim contenteditable class="xml">
<repository>
<id>boundless</id>
<name>Boundless Maven Repository</name>
<url>http://repo.boundlessgeo.com/main</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<dependency>
<groupId>org.geoscript</groupId>
<artifactId>geoscript-groovy</artifactId>
<version>1.3</version>
</dependency>
</code>
</pre>
</section>
<section>
<div style="text-align: right;">
<img src="img/gradle-logo.png"></img>
</div>
<pre>
<code data-trim contenteditable class="groovy">
repositories {
maven {
url "http://repo.boundlessgeo.com/main"
}
}
dependencies {
compile "org.geoscript:geoscript-py:1.3"
}
</code>
</pre>
</section>
</section>
<section>
<div>
<a class="image" href="https://www.locationtech.org/">
<img src="img/locationtech-logo.png"></img>
</a>
</div>
<h4>
<a href="http://locationtech.org">http://locationtech.org</a>
</h4>
</section>
<section>
<section>
<h2>Some Real World Examples</h2>
<div style="float: left; width: 50%;">
<p>
Land Area Statistics
</p>
</div>
<div style="float: left; width: 50%;">
<p>
WNV Spatial Analysis
</p>
</div>
</section>
<section>
<h2>WNV Spatial Analysis</h2>
<p>Goal was to create an animated map showing spread of WNV by state</p>
</section>
<section>
<p>CDC Data in PDF</p>
<img src="img/wnv_pdf.png"/>
</section>
<section>
<p>Get Text from PDF</p>
<pre>
<code data-trim contenteditable class="groovy">
@Grapes(
@Grab(group='com.lowagie', module='itext', version='2.1.7')
)
import com.lowagie.text.pdf.parser.PdfTextExtractor
import com.lowagie.text.pdf.PdfReader
// Use iText to extract text from PDF
URL url = new URL("http://www.cdc.gov/westnile/resources/pdfs/cummulative/99_2013_cummulativeHumanCases.pdf")
PdfReader reader = new PdfReader(url)
PdfTextExtractor parser =new PdfTextExtractor(reader)
// Write text to a file in the data directory
File dir = new File("data")
dir.mkdir()
File file = new File(dir, "data.dat")
file.write(parser.getTextFromPage(1))
</code>
</pre>
</section>
<section>
<p>Convert text into CSV</p>
<pre>
<code data-trim contenteditable class="groovy">
State,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,Total
Alabama,0,0,2,49,37,16,10,8,24,18,0,3,5,62,9,243
Alaska,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Arizona,0,0,0,0,13,391,113,150,97,114,20,167,69,133,62,1329
Arkansas,0,0,0,43,25,28,28,29,20,9,6,7,1,64,18,278
...
</code>
</pre>
</section>
<section>
<p>Get data from Natural Earth</p>
<pre>
<code data-trim contenteditable class="groovy">
URL url = new URL("http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_1_states_provinces_lakes.zip")
File file = new File("data/ne_110m_admin_1_states_provinces_lakes.zip")
if (!file.exists()) {
url.withInputStream { inp ->
file.withOutputStream { out ->
out << inp
}
}
}
File dir = new File("data")
def ant = new AntBuilder()
ant.unzip(src: file, dest: dir)
</code>
</pre>
</section>
<section>
<p>Join WNV Data to Natural Earth data</p>
<pre>
<code data-trim contenteditable class="groovy">
Workspace wk = new Directory("data")
Layer inLayer = wk.get("ne_110m_admin_1_states_provinces_lakes")
Schema schema = inLayer.schema
Schema newSchema = schema.addFields(newFields, "states")
Layer outLayer = wk.create(newSchema)
outLayer.withWriter { Writer w ->
inLayer.eachFeature { Feature f ->
w.add(f)
}
}
lines.subList(1, lines.size()).each { String line ->
List items = line.split(",")
String name = items[0]
if (name.equals("Dist. of")) {
name = "District of Columbia"
}
Filter filter = new Filter("name='${name}'")
items.eachWithIndex{ String item, int c ->
String fieldName = fieldNames[c]
if (!fieldName.equals("State")) {
Field field = outLayer.schema.field("y" + fieldName)
outLayer.update(field, Double.parseDouble(item), filter)
}
}
}
</code>
</pre>
</section>
<section>
<p>Draw maps of WNV spread for each year</p>
<pre>
<code data-trim contenteditable class="groovy">
List images = years.collect { String year ->
String name = "y${year}"
Field field = layer.schema.get(name)
Gradient style = new Gradient(layer, field, "EqualInterval", 5, "Reds")
layer.style = style
Map map = new Map(
layers: [osm, layer],
bounds: layer.bounds.expandBy(0.3),
proj: layer.proj,
backgroundColor: "white",
type: "gif"
)
def image = map.renderToImage()
def graphics = image.graphics
graphics.paint = Color.BLACK
graphics.font = new java.awt.Font("Arial", java.awt.Font.BOLD, 32)
graphics.drawString(year,5,30)
graphics.dispose()
ImageIO.write(image, "gif", new File(dir, "${year}.gif"))
image
}
GIF gif = new GIF()
gif.renderAnimated(images, new File(dir, "wnv.gif"), 1000)
</code>
</pre>
</section>
<section>
<p>WNV Spread by Year</p>
<img src="img/wnv.gif"/>
</section>
<section>
<h2>Protected Lands Classification</h2>
<p>Goal is to analyze protected lands usage for specific area.</p>
</section>
<section>
<img src="img/lands.png"></img>
<a style="font-size: 16px; text-decoration: underline;" href="http://localhost:9000" target="_blank">Demo</a>
</section>
</section>
<section>
<h1>Thanks</h1>
<h4><a href="http://geoscript.org">http://geoscript.org</a></h4>
<h4><a href="mailto:[email protected]">[email protected]</a></h4>
</section>
</div>
</div>
<script src="lib/js/jquery-1.11.1.min.js"></script>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
backgroundTransition: 'slide',
transition: 'linear',
//transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Parallax scrolling
// parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg',
// parallaxBackgroundSize: '2100px 900px',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
// $(document).ready(function() {
// $('.slides > section').each(function(i) {
// $(this).attr('data-state', i===0?'initial':'slide');
// });
// });
Reveal.addEventListener('slidechanged', function(e) {
$('header').toggle(e.indexh === 0);
});
Reveal.addEventListener('fragmentshown', function(e) {
$.each(e.fragments, function(f) {
$(f).show();
});
});
Reveal.addEventListener('fragmenthidden', function(e) {
$.each(e.fragments, function(f) {
$(f).hide();
});
});
// Reveal.addEventListener('initial', function() {
// $('header').show();
// });
// Reveal.addEventListener('slide', function() {
// $('header').hide();
// });
</script>
</body>
</html>