forked from jseppi/intro-to-turf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
328 lines (314 loc) · 17.6 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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<meta name="author" content="James Seppi | @hydrologee" />
<title>Intro to Turf.js</title>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; background-color: #303030; color: #cccccc; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; }
td.sourceCode { padding-left: 5px; }
pre, code { color: #cccccc; background-color: #303030; }
code > span.kw { color: #f0dfaf; }
code > span.dt { color: #dfdfbf; }
code > span.dv { color: #dcdccc; }
code > span.bn { color: #dca3a3; }
code > span.fl { color: #c0bed1; }
code > span.ch { color: #dca3a3; }
code > span.st { color: #cc9393; }
code > span.co { color: #7f9f7f; }
code > span.ot { color: #efef8f; }
code > span.al { color: #ffcfaf; }
code > span.fu { color: #efef8f; }
code > span.er { color: #c3bf9f; }
</style>
<link rel="stylesheet" type="text/css" media="screen, projection, print"
href="http://www.w3.org/Talks/Tools/Slidy2/styles/slidy.css" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script src="//api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<link rel="stylesheet" href="styles/style.css" />
<script src="http://www.w3.org/Talks/Tools/Slidy2/scripts/slidy.js"
charset="utf-8" type="text/javascript"></script>
</head>
<body>
<div class="slide titlepage">
<h1 class="title">Intro to Turf.js</h1>
<p class="author">
James Seppi | <span class="citation">@hydrologee</span>
</p>
<p class="date">MaptimeATX - June 10, 2015</p>
</div>
<div id="intro-to-turf.js" class="slide section level1">
<h1>Intro to Turf.js</h1>
<p>Presentation at <a href="http://www.meetup.com/MaptimeATX/events/222643093/">MaptimeATX</a></p>
<p>Viewable at <a href="http://maptimeatx.github.io/intro-to-turf">maptimeatx.github.io/intro-to-turf</a></p>
<p>Source code at <a href="https://github.com/MaptimeATX/intro-to-turf/">github.com/MaptimeATX/intro-to-turf/</a></p>
</div>
<div id="about-turf.js" class="slide section level1">
<h1>About Turf.js</h1>
<p>Project started and managed by <a href="https://github.com/morganherlocker">Morgan Herlocker</a> (now at <a href="http://mapbox.com">Mapbox</a>)</p>
<div class="figure">
<img src="img/morganherlocker.jpg" />
</div>
</div>
<div id="about-turf.js-1" class="slide section level1">
<h1>About Turf.js</h1>
<p><a href="http://turfjs.org">turfjs.org</a></p>
<p><a href="https://github.com/turfjs">github.com/turfjs</a></p>
<div class="figure">
<img src="img/turflogo.png" />
</div>
<p>1280+ stars, 15 owners</p>
<div class="figure">
<img src="img/owners.png" />
</div>
</div>
<div id="ok-but-what-is-it" class="slide section level1">
<h1>Ok, but what is it?</h1>
<p>JavaScript library for <strong>geospatial analysis</strong></p>
<div class="incremental">
<p>Runs in web browsers, or in <a href="http://nodejs.org">Node.js</a></p>
</div>
<div class="incremental">
<p>Open Source, MIT-licensed</p>
</div>
<div class="incremental">
<p>Collection of small modules</p>
</div>
</div>
<div id="modules" class="slide section level1">
<h1>Modules</h1>
<p>Aggregation, Measurement, Transformation, Interpolation, Classification, Joins, Types, and Helpers</p>
<div class="incremental">
<p>turf-area</p>
</div>
<div class="incremental">
<p>turf-buffer</p>
</div>
<div class="incremental">
<p>turf-distance</p>
</div>
<div class="incremental">
<p>turf-intersect, turf-union, turf-merge</p>
</div>
<div class="incremental">
<p>turf-aggregate, turf-along, turf-average, turf-bbox-polygon, turf-bearing, turf-bezier, turf-center, turf-centroid, turf-combine, turf-concave, turf-convex, turf-count, turf-destination, turf-deviation, turf-envelope, turf-erase, turf-explode, turf-extent, turf-featurecollection, turf-filter, turf-flip, turf-hex-grid, turf-inside, turf-isolines, turf-jenks, turf-kinks, turf-line-distance, turf-line-slice, turf-linestring, turf-max, turf-median, turf-midpoint, turf-min, turf-nearest, turf-planepoint, turf-point, turf-point-grid, turf-point-on-line, turf-point-on-surface, turf-polygon, turf-quantile, turf-random, turf-reclass, turf-remove, turf-sample, turf-simplify, turf-size, turf-square, turf-square-grid, turf-sum, turf-tag, turf-tin, turf-triangle-grid, turf-variance, turf-within</p>
</div>
</div>
<div id="data-format" class="slide section level1">
<h1>Data Format</h1>
<p>Uses <a href="http://geojson.org"><strong>GeoJSON</strong></a> for all data in and out</p>
<div class="incremental">
<p><strong>Geographic coordinates</strong> (WGS-84) only</p>
</div>
<div class="incremental">
<p>This means you must first <em>reproject</em> and <em>transform</em> other data formats to GeoJSON to use it in Turf</p>
</div>
</div>
<div id="geojson" class="slide section level1">
<h1>GeoJSON</h1>
<p>Standard format for geospatial data on the web</p>
<div class="incremental">
<p>Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection</p>
</div>
<div class="incremental">
<p>Feature, FeatureCollection (store properties with geometries)</p>
</div>
</div>
<div id="geojson-1" class="slide section level1">
<h1>GeoJSON</h1>
<pre class="sourceCode json"><code class="sourceCode json"><span class="fu">{</span>
<span class="dt">"type"</span><span class="fu">:</span> <span class="st">"Feature"</span><span class="fu">,</span>
<span class="dt">"geometry"</span><span class="fu">:</span> <span class="fu">{</span>
<span class="dt">"type"</span><span class="fu">:</span> <span class="st">"Point"</span><span class="fu">,</span>
<span class="dt">"coordinates"</span><span class="fu">:</span> <span class="ot">[</span><span class="fl">-97.74306</span><span class="ot">,</span> <span class="fl">30.26715</span><span class="ot">]</span>
<span class="fu">},</span>
<span class="dt">"properties"</span><span class="fu">:</span> <span class="fu">{</span>
<span class="dt">"name"</span><span class="fu">:</span> <span class="st">"Austin"</span><span class="fu">,</span>
<span class="dt">"population"</span><span class="fu">:</span> <span class="dv">885400</span>
<span class="fu">}</span>
<span class="fu">}</span></code></pre>
<p><a href="http://geojson.org">geojson.org</a></p>
<p><a href="http://geojson.io">geojson.io</a></p>
<p>GitHub renders it: <a href="https://github.com/tnris/tx.geojson">github.com/tnris/tx.geojson</a></p>
</div>
<div id="using-turf" class="slide section level1">
<h1>Using Turf</h1>
<p>In Node:</p>
<pre class="sourceCode javascript"><code class="sourceCode javascript">npm install turf
<span class="co">//or npm install turf-buffer</span>
<span class="kw">var</span> turf = <span class="fu">require</span>(<span class="st">'turf'</span>);
<span class="co">//or var buffer = require('turf-buffer');</span></code></pre>
<div class="incremental">
<p>On your web page</p>
<pre class="sourceCode html"><code class="sourceCode html"><span class="kw"><script</span><span class="ot"> src=</span><span class="st">"//api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"</span><span class="kw">></span>
<span class="kw"></script></span>
<span class="kw"><script></span>
<span class="kw">var</span> bufferedPoint = <span class="ot">turf</span>.<span class="fu">buffer</span>(myPoint, <span class="dv">5</span>, <span class="st">'miles'</span>);
<<span class="ot">/script></span></code></pre>
</div>
</div>
<div id="examples" class="slide section level1">
<h1>Examples!</h1>
<p>Word of Warning: Having too many points or complex features will make rendering or non-responsive</p>
<p>For larger datasets or complex analysis, it is better to do analysis on back-end</p>
</div>
<div class="slide section level1">
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="kw">var</span> austin = <span class="ot">turf</span>.<span class="fu">point</span>([-<span class="fl">97.743061</span>, <span class="fl">30.267153</span>]); <span class="co">//GeoJSON point</span>
<span class="kw">var</span> buffered = <span class="ot">turf</span>.<span class="fu">buffer</span>(austin, <span class="dv">15</span>, <span class="st">'miles'</span>);
result = <span class="ot">turf</span>.<span class="fu">featurecollection</span>([austin, buffered])</code></pre>
<button class="button">
Show Demo
</button>
</div>
<div class="slide section level1">
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="kw">var</span> austin = <span class="ot">turf</span>.<span class="fu">point</span>([-<span class="fl">97.743061</span>, <span class="fl">30.267153</span>]); <span class="co">//GeoJSON point</span>
<span class="kw">var</span> atxBuffer = <span class="ot">turf</span>.<span class="fu">buffer</span>(austin, <span class="dv">15</span>, <span class="st">'miles'</span>);
<span class="kw">var</span> roundrock = <span class="ot">turf</span>.<span class="fu">point</span>([-<span class="fl">97.678896</span>, <span class="fl">30.508255</span>]);
<span class="kw">var</span> rrBuffer = <span class="ot">turf</span>.<span class="fu">buffer</span>(roundrock, <span class="dv">15</span>, <span class="st">'miles'</span>);
result = <span class="ot">turf</span>.<span class="fu">union</span>(<span class="ot">atxBuffer</span>.<span class="fu">features</span>[<span class="dv">0</span>], <span class="ot">rrBuffer</span>.<span class="fu">features</span>[<span class="dv">0</span>]);</code></pre>
<button class="button">
Show Demo
</button>
</div>
<div class="slide section level1">
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="kw">var</span> austin = <span class="ot">turf</span>.<span class="fu">point</span>([-<span class="fl">97.743061</span>, <span class="fl">30.267153</span>]); <span class="co">//GeoJSON point</span>
<span class="kw">var</span> atxBuffer = <span class="ot">turf</span>.<span class="fu">buffer</span>(austin, <span class="dv">15</span>, <span class="st">'miles'</span>);
<span class="kw">var</span> roundrock = <span class="ot">turf</span>.<span class="fu">point</span>([-<span class="fl">97.678896</span>, <span class="fl">30.508255</span>]);
<span class="kw">var</span> rrBuffer = <span class="ot">turf</span>.<span class="fu">buffer</span>(roundrock, <span class="dv">15</span>, <span class="st">'miles'</span>);
result = <span class="ot">turf</span>.<span class="fu">intersect</span>(<span class="ot">atxBuffer</span>.<span class="fu">features</span>[<span class="dv">0</span>], <span class="ot">rrBuffer</span>.<span class="fu">features</span>[<span class="dv">0</span>]);</code></pre>
<button class="button">
Show Demo
</button>
</div>
<div class="slide section level1">
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="co">//City of Austin Historical Landmarks</span>
<span class="co">// from https://data.austintexas.gov/Geodata/Historical-Landmarks-Map/6k54-2nnj</span>
display = <span class="ot">landmarks</span>.<span class="fu">type</span>;
display = <span class="st">'Num Points: '</span> + <span class="ot">landmarks</span>.<span class="ot">features</span>.<span class="fu">length</span>;
result = landmarks;</code></pre>
<button class="button">
Show Demo
</button>
<p>Download the Historical Landmarks GeoJSON at <a href="http://maptimeatx.github.io/intro-to-turf/data/landmarks.geojson">maptimeatx.github.io/intro-to-turf/data/landmarks.geojson</a></p>
</div>
<div class="slide section level1">
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="kw">var</span> bbox = <span class="ot">turf</span>.<span class="fu">extent</span>(landmarks);
<span class="kw">var</span> grid = <span class="ot">turf</span>.<span class="fu">squareGrid</span>(bbox, <span class="fl">0.5</span>, <span class="st">'miles'</span>);
<span class="kw">var</span> counted = <span class="ot">turf</span>.<span class="fu">count</span>(grid, landmarks, <span class="st">'pointCount'</span>);
result = counted;</code></pre>
<button class="button">
Show Demo
</button>
</div>
<div class="slide section level1">
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="kw">var</span> bbox = <span class="ot">turf</span>.<span class="fu">extent</span>(landmarks);
<span class="kw">var</span> grid = <span class="ot">turf</span>.<span class="fu">hexGrid</span>(bbox, <span class="fl">0.5</span>, <span class="st">'miles'</span>);
<span class="kw">var</span> counted = <span class="ot">turf</span>.<span class="fu">count</span>(grid, landmarks, <span class="st">'pointCount'</span>);
result = counted;</code></pre>
<button class="button">
Show Demo
</button>
</div>
<div id="documentation" class="slide section level1">
<h1>Documentation!</h1>
<p>Documentation is a top priority for the Turf project</p>
<div class="figure">
<img src="img/turfdocs.png" />
</div>
</div>
<div id="documentation-1" class="slide section level1">
<h1>Documentation!</h1>
<p>Built directly from the source code</p>
<div class="incremental">
<div class="figure">
<img src="img/turfdocs2.png" alt="Interactive examples!" />
<p class="caption">Interactive examples!</p>
</div>
</div>
</div>
<div id="in-the-wild" class="slide section level1">
<h1>In the Wild</h1>
<div class="figure">
<img src="img/hex_temp_jvrousseau.png" alt="Average Temperature by Jordan Rousseau" />
<p class="caption">Average Temperature by <a href="https://twitter.com/jvrousseau">Jordan Rousseau</a></p>
</div>
</div>
<div class="slide section level1">
<div class="figure">
<img src="img/tornadoes.png" alt="Analysis of 60 Years of Tornadoes - mapbox.com/blog/60-years-of-tornadoes-with-turf" />
<p class="caption">Analysis of 60 Years of Tornadoes - <a href="https://www.mapbox.com/blog/60-years-of-tornadoes-with-turf/">mapbox.com/blog/60-years-of-tornadoes-with-turf</a></p>
</div>
<p>57,988 tornadoes analyzed over 3,221 counties (in <a href="http://nodejs.org">Node</a>)</p>
</div>
<div class="slide section level1">
<div class="figure">
<img src="img/iditarod.png" alt="Iditarod Visualization - mapbox.com/blog/playback-the-iditarod-with-turf" />
<p class="caption">Iditarod Visualization - <a href="https://www.mapbox.com/blog/playback-the-iditarod-with-turf/">mapbox.com/blog/playback-the-iditarod-with-turf</a></p>
</div>
</div>
<div id="get-involved" class="slide section level1">
<h1>Get Involved</h1>
<p>Open Source, developed in the open on GitHub: <a href="https://github.com/turfjs">github.com/turfjs</a></p>
<div class="incremental">
<p>Still more work to be done: <strong>docs</strong> to improve, <strong>code</strong> to write, <strong>bugs</strong> to discover, <strong>tests</strong> to write</p>
</div>
<div class="incremental">
<p>Check out the issues: <a href="https://github.com/turfjs/turf/issues">github.com/turfjs/turf/issues</a></p>
</div>
</div>
<div id="hands-on" class="slide section level1">
<h1>Hands-On!</h1>
<p><a href="https://jsfiddle.net/jseppi/grwh8kmx/4/">jsfiddle.net/jseppi/grwh8kmx/4/</a></p>
<div class="incremental">
<p>Pair up with some (new) friends. Try to have a JavaScript person in each group.</p>
</div>
<div class="incremental">
<p>Work together. Ask questions. You can do it!</p>
</div>
<div class="incremental">
<div class="figure">
<img src="http://cdn.meme.am/instances/500x/56977270.jpg" />
</div>
</div>
</div>
<div id="notes-about-hands-on-data" class="slide section level1">
<h1>Notes about Hands-On Data</h1>
<p><strong>Austin Historic Landmarks</strong></p>
<ul>
<li>GeoJSON: <a href="https://maptimeatx.github.io/intro-to-turf/data/historic_landmarks.geojson">maptimeatx.github.io/intro-to-turf/data/historic_landmarks.geojson</a></li>
<li>Modified from: <a href="https://data.austintexas.gov/dataset/Historical-Landmarks/nrfx-jets">data.austintexas.gov/dataset/Historical-Landmarks/nrfx-jets</a></li>
</ul>
<p><strong>Austin City Council Districts</strong></p>
<ul>
<li>GeoJSON: <a href="https://maptimeatx.github.io/intro-to-turf/data/austin_districts.geojson">maptimeatx.github.io/intro-to-turf/data/austin_districts.geojson</a></li>
<li>Modified from: <a href="https://data.austintexas.gov/Government/Single-Member-Council-Districts/69pm-tzkv">data.austintexas.gov/Government/Single-Member-Council-Districts/69pm-tzkv</a></li>
</ul>
</div>
<div class="slide section level1">
</div>
<div id="answers" class="slide section level1">
<h1>Answers</h1>
<p>Don't Peak!</p>
<div class="incremental">
<ul>
<li>Center: <a href="https://jsfiddle.net/jseppi/5pgzdtpz/1/" class="uri">https://jsfiddle.net/jseppi/5pgzdtpz/1/</a></li>
<li>Merge: <a href="https://jsfiddle.net/6eo46j64/3/" class="uri">https://jsfiddle.net/6eo46j64/3/</a></li>
<li>Number in each: <a href="http://jsfiddle.net/jseppi/bxw7o6hb/5/" class="uri">http://jsfiddle.net/jseppi/bxw7o6hb/5/</a></li>
<li>Landmarks in District 9: <a href="https://jsfiddle.net/at6mukbc/2/" class="uri">https://jsfiddle.net/at6mukbc/2/</a></li>
<li>Centroids: <a href="https://jsfiddle.net/jseppi/f9vov2s3/3/" class="uri">https://jsfiddle.net/jseppi/f9vov2s3/3/</a></li>
</ul>
</div>
</div>
<script src="scripts/main.js"></script>
</body>
</html>