๐Ÿ‘ถ๐Ÿ‘ง๐Ÿ‘ฉ
What is TurfJS?
Advanced geospatial analysis for browsers and Node.js
Modular => Area, Bounding Box, Buffer, Grids, Intersect, Isolines, Length, Random, Sample, Voroni, Within...
JavaScript functions that speak GeoJSON
What is GeoJSON?

/** GeoJSON is a single JSON file containing one or more features */
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [-82, 39] /*WGS 84*/
      },
      "properties": {
        "field": "value"
      }
    }
  ]
}
GeoJSON is Everywhere

ArcGIS Feature to JSON
USGS Earthquake Feed
DATA.GOV (1,600+ Datasets)
AGOL Query Response & Exports
geojson.xyz (Natural Earth Data+)
Native Support in QGIS

GitHub Support (2013)

Free & Open

Source Software
github.com/Turfjs

# Include in your HTML
https://cdnjs.cloudflare.com/ajax/libs/Turf.js/5.1.5/turf.min.js


# Install via NodeJS
npm install @turf/turf --OR-- npm install @turf/bbox
Why use TurfJS?
Simple geospatial queries
Complex geospatial analysis (in NodeJS)
Creating spatial metadata (bounding box)
A Few Examples
Turf Within
turf.booleanWithin(point, polygon)

Where am I?


var result = "";
counties.features.map(function(county) {
  var point = turf.point([x,y]);
    if (turf.booleanWithin(point, county) {
      result = county.properties.NAME;
    }
});
Click the Submit button on the previous page
๐Ÿคฏ๐Ÿ˜ต๐Ÿง
๐Ÿคจ๐Ÿ˜ญ๐Ÿ˜•
Practical Applications
Local Authoritative Open Data
Turf Nearest
Array.filter()
turf.nearestPoint(point, points)
# Find the Closest Playground

var data = amenities.features.filter(function(a) {
  return a.properties.TYPE === 'Playground' 
})

var playgrounds = turf.featureCollection(data);

var result = turf.nearestPoint(point, playgrounds)

Loading...
๐Ÿ˜๐Ÿ˜๐Ÿ˜
Advanced Analysis in TurfJS
๐Ÿจ๐Ÿ˜ด๐Ÿ’ค
Visualizing Crashes in Muskingum County (>7k)
Hexgrids
turf.hexGrid(bbox, size, opts)
Intersect
turf.intersect(a,b)
Collect
turf.collect(p, pts, field, name)

Turf Hexgrids


var bbox = [-82.5, 39.7, -81.5, 40.18];
var size = 1;
var options = {
  units: 'miles'
};

var hexgrid = turf.hexGrid(bbox, size, options)

Turf Intersect

// loop through each grid
// add the intersecting areas to the clippedGrid
// calculate the area in sq miles

var clippedGrid = { โ€œtypeโ€:โ€FeatureCollectionโ€, โ€œfeaturesโ€:[] }

hexgrid.features.map(function(grid) {
var toFt = 0.00000386102159
var intersect = turf.intersect(grid, muskingum);
if (intersect) {
intersect.properties.area = (turf.area(intersect)) * toFt;
clippedGrid.features.push(intersect);
}
});

Turf Collect
turf.collect(clippedGrid, crashes, "count", "total")
Turf in Node JS
Find the Nearest ๐Ÿ•๏ธ National Park
45MB GeoJSON Park Boundary File
var points = turf.explode(polygon)
turf.nearestPoint(point, points)
Query NodeJS
No Node JS Server Running! Tested Benchmark ~ 2 seconds

No Coding
Dropchop

Support TurfJS

Thanks!
Malcolm Meyer
@getbounds