alpha-shape icon indicating copy to clipboard operation
alpha-shape copied to clipboard

How to use alpha-shapes with GeoJSON

Open nikolauskrismer opened this issue 8 years ago • 4 comments

The demo you provided looks great. Good work!

I tried to use your code to generate an alpha-shape around geographical coordinates, but here I am a bit stuck on how to use your return value. My code uses GeoJSON, so I first extracted points to calculate the alpha-shape from.

I am not sure what the returned value means, but first I thought that the returned array will contain coordinates as well. That's obviously not the case, since the values returned are far off the coordinates given (my coordinates are around 11.35 and 46.50, the values returned are often above 100). So I thought that the actual coordinates need to be read from the input value (that the returned array references the values in the input array). Using the parameter this way works somehow, but does not deliver anything near to the result I expected.

I created a JSFiddle 1 with the input array and the expected result: http://jsfiddle.net/Niko_K/weqfy733/ Could you please elaborate a bit on how to use your function's return value and how to exactly use you code to create an alpha-shape that is near the exact solution given in the JSFiddle (and not the red one that I get when calling your function with an alpha value of 10)?

nikolauskrismer avatar Sep 21 '16 11:09 nikolauskrismer

Were you able to figure out the meaning of the return value? I'm struggling with it even with the example in README.

asmarcz avatar Feb 06 '19 07:02 asmarcz

No I was not able to figure out what the return value means. Sorry...

nikolauskrismer avatar Feb 09 '19 13:02 nikolauskrismer

@nikolauskrismer, @asmarcz

I analyzed demo code and figured out that return values are indices of original points array.

https://github.com/mikolalysenko/alpha-shape/blob/master/viewer.js#L45-L57

alphaHull is the return value of the algoritm here. points is the original array of points.

And to get array of calculated contours you can simply use this code:

for(let i=0; i<alphaHull.length; i++) {
    let cell = alphaHull[i]; // cell is calculated contour (there can be many of them)
    for(var j=0; j<cell.length; j++) {
      console.log(points[cell[j]]); // cell[j] contains index of contour point in original array, so we should use points[cell[j]] to get coordinates
    }
  }

Sc222 avatar Feb 18 '22 13:02 Sc222

Thank you, random stranger, I've completely forgotten, what is the purpose of the library and barely remember where I've used it. I will definitely check it out later tho!

asmarcz avatar Feb 18 '22 15:02 asmarcz