% Intro to Turf.js % James Seppi % TNRIS GeoRodeo - May 22, 2015
Presentation by James Seppi
Software Developer at TNRIS, part of TWDB
Twitter: hydrologee
Viewable at jseppi.github.io/intro-to-turf/
Source code at github.com/jseppi/intro-to-turf/
JavaScript library for geospatial analysis
. . .
Runs in the browser, or in Node.js
. . .
Open Source, MIT-licensed
Collection of small modules
. . .
(from Tom MacWright - macwright.org/presentations/turf-geodc)
. . .
2000: Java Topology Suite (JTS)
. . .
2003: GEOS, JTS port to C++
. . .
2008: Shapely, interface of GEOS to Python
. . .
2011: JavaScript Topology Suite (JSTS), JTS port to JS
. . .
2014: Turf
Not a port, new implementations
. . .
Project started and managed by Morgan Herlocker (now at Mapbox)
. . .
1280+ stars, 15 owners
Aggregation, Measurement, Transformation, Interpolation, Classification, Joins, Types, and Helpers
. . .
turf-area
. . .
turf-buffer
. . .
turf-distance
. . .
turf-intersect, turf-union, turf-merge
. . .
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
New implementations, recent algorithms - pretty fast!
. . .
"Isomorphic" - browser and back-end
. . .
Modular - take only what you need (good for browsers via browserify)
. . .
Speaks GeoJSON
. . .
Wraps other modules so that they speak GeoJSON, too
. . .
Not GeoJohnson
Lingua franca for geospatial data on the web
. . .
Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection
. . .
Feature, FeatureCollection (store properties with geometries)
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
GitHub renders it: github.com/tnris/tx.geojson
In Node:
npm install turf
//or npm install turf-buffer
var turf = require('turf');
//or var buffer = require('turf-buffer');
. . .
On your web page
<script src="//api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js">
</script>
<script>
var bufferedPoint = turf.buffer(myPoint, 5, 'miles');
</script>
Word of Warning: Web map rendering performance
For larger datasets do analysis on back-end
. . .
Nonetheless, it is fun to see in a web map
var austin = turf.point([-97.743061, 30.267153]); //GeoJSON point
var buffered = turf.buffer(austin, 15, 'miles');
result = turf.featurecollection([austin, buffered])
Show Demo
var austin = turf.point([-97.743061, 30.267153]); //GeoJSON point
var atxBuffer = turf.buffer(austin, 15, 'miles');
var roundrock = turf.point([-97.678896, 30.508255]);
var rrBuffer = turf.buffer(roundrock, 15, 'miles');
result = turf.union(atxBuffer.features[0], rrBuffer.features[0]);
Show Demo
var austin = turf.point([-97.743061, 30.267153]); //GeoJSON point
var atxBuffer = turf.buffer(austin, 15, 'miles');
var roundrock = turf.point([-97.678896, 30.508255]);
var rrBuffer = turf.buffer(roundrock, 15, 'miles');
result = turf.intersect(atxBuffer.features[0], rrBuffer.features[0]);
Show Demo
//tnris geojson made with rasterio
display = tnris.type;
result = tnris;
Show Demo
result = turf.explode(tnris);
display = 'Num Points: ' + result.features.length;
Show Demo
var merged = turf.merge(tnris);
var polys = merged.geometry.coordinates.map(function (c) {
return turf.simplify(turf.polygon(c), 0.1);
});
result = turf.featurecollection(polys);
Show Demo
//use simplified result from previous example
result = turf.explode(result);
display = 'Num Points: ' + result.features.length;
Show Demo
//use exploded result from previous example
result = turf.tin(result);
Show Demo
var bbox = turf.extent(tnris);
var grid = turf.squareGrid(bbox, 50, 'miles');
var points = turf.explode(tnris);
var counted = turf.count(grid, points, 'pointCount');
result = counted;
Show Demo
var bbox = turf.extent(tnris);
var grid = turf.triangleGrid(bbox, 50, 'miles');
var points = turf.explode(tnris);
var counted = turf.count(grid, points, 'pointCount');
result = counted;
Show Demo
var bbox = turf.extent(tnris);
var grid = turf.hexGrid(bbox, 50, 'miles');
var points = turf.explode(tnris);
var counted = turf.count(grid, points, 'pointCount');
result = counted;
Show Demo
Documentation has been at the forefront of development by the core team
. . .
(especially: morganherlocker, tmcw, lyzidiamond, tchannel)
Built directly from the source code
. . .
57,988 tornadoes analyzed over 3,221 counties (in Node)
Open Source, developed in the open on GitHub: github.com/turfjs
. . .
Still more work to be done: docs to improve, code to write, bugs to discover, tests to write
. . .
Check out the issues: github.com/turfjs/turf/issues
Austin Open Source GIS User Group