Turf: [@turf/concave] Returns a convex hull instead of a concave one

Created on 7 Jul 2018  路  4Comments  路  Source: Turfjs/turf

Not sure if it always happen, but here is an example of coordinates for which the hull is not concave. Just to be sure that we talk about the same concave hull, here is what I expect:

My version is @turf/[email protected] but it seems like the same bug appears on older versions too.

Most helpful comment

Looking at this a bit further we should probably change out our algorithm for concaveman

All 4 comments

Hi @cglacet

Have you tried adjusting the maxEdge option, perhaps try setting it to 0 and slowly adjusting upward?

Hello!

No I haven't try, I will as soon as I can. But shouldn't a larger maxEdge allow for a longer perimeter hull and thus a better concave fit to my input?

Looking at this a bit further we should probably change out our algorithm for concaveman

I updated the gist with the comparison _Turf vs. Concaveman_. The result from Concaveman seems way closer to what I expected in the first place.

Of course this is just one example and it doesn't prove Concaveman is good, but it's a start for me.

In case someone needs this too, here is the code I used to test both the Turf and the Concaveman versions (with input.json):

import testPoints from './input.json';
import concaveman from 'concaveman';
import turfConcave from '@turf/concave';
import { polygon as turfPolygon, featureCollection } from '@turf/helpers';

function turfConcaveman(points:FeatureCollection<Point>){
   const coordinates = points.features.map(f => f.geometry.coordinates);
   return turfPolygon([concaveman(coordinates)]);
}

const turf = {
   polygon: turfPolygon,
   featureCollection,
   concaveman: turfConcaveman,
   concave: turfConcave,
};

const polygonCave = turf.concaveman(testPoints);
const polygonTurf = turf.concave(testPoints);
console.log(JSON.stringify(turf.featureCollection([polygonTurf, polygonCave, ...testPoints.features])));
Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexgleith picture alexgleith  路  5Comments

privateOmega picture privateOmega  路  3Comments

dhivehi picture dhivehi  路  5Comments

DenisCarriere picture DenisCarriere  路  3Comments

robhawkes picture robhawkes  路  3Comments