Skip to content

Instantly share code, notes, and snippets.

@morganherlocker
Created February 6, 2015 17:43
Show Gist options
  • Select an option

  • Save morganherlocker/ace177825879ff203733 to your computer and use it in GitHub Desktop.

Select an option

Save morganherlocker/ace177825879ff203733 to your computer and use it in GitHub Desktop.

turf-concave

build status

turf concave module

turf.concave(points, maxEdge, units)

Takes a FeatureCollection of Point features and returns a concave hull.

Internally, this implements a Monotone chain algorithm.

Parameters

parameter type description
points FeatureCollection a FeatureCollection of Point features
maxEdge number the size of an edge necessary for part of the hull to become concave (in miles)
units String used for maxEdge distance (miles or kilometers)

Example

var points = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.601226, 44.642643]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.591442, 44.651436]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.580799, 44.648749]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.573589, 44.641788]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.587665, 44.64533]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.595218, 44.64765]
      }
    }
  ]
};

var hull = turf.concave(points, 1);

var resultFeatures = points.features.concat(hull);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

Returns Feature, a Polygon feature

Installation

Requires nodejs.

$ npm install turf-concave

Tests

$ npm test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment