Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lineSliceAlong fails #1710

Closed
tpolong opened this issue Jun 8, 2019 · 6 comments
Closed

lineSliceAlong fails #1710

tpolong opened this issue Jun 8, 2019 · 6 comments

Comments

@tpolong
Copy link

tpolong commented Jun 8, 2019

 var route = {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [[112.2998991, 22.0126324], [112.2996097, 22.0134472], [112.2996597, 22.0133881], [112.2777231, 22.0164887], [112.2774728, 22.0166772], [112.2774033, 22.0165736], [112.2775611, 22.0164055], [112.2776283, 22.0161038], [112.2776846, 22.0163612], [112.2776739, 22.0163395], [112.2776479, 22.0163987], [112.2776427, 22.0162798], [112.2775763, 22.016116], [112.2777229, 22.0161367], [112.2777592, 22.0161772], [112.2777634, 22.0162569], [112.277711, 22.0162228], [112.2776429, 22.0159677], [112.2777159, 22.0164053], [112.2777012, 22.0164482], [112.2777467, 22.0159461], [112.2774918, 22.016228], [112.2777323, 22.0163755], [112.27788, 22.0156734], [112.2777364, 22.0161047], [112.2777321, 22.0154175], [112.2775976, 22.0159372], [112.2775141, 22.0164522], [112.2773987, 22.0163157], [112.2777456, 22.016317], [112.2777335, 22.0160323], [112.2776058, 22.0159735], [112.2776119, 22.0162441], [112.277613, 22.0162797], [112.2776901, 22.0159297], [112.2776718, 22.0159579], [112.2776664, 22.0160062], [112.2776555, 22.0160424], [112.2776822, 22.0163974], [112.2776653, 22.0165653], [112.277671, 22.0165485], [112.2776557, 22.0165534], [112.2776157, 22.0157634], [112.2777147, 22.0160169], [112.2777923, 22.0161012], [112.2777863, 22.0160907], [112.2777051, 22.016329], [112.2777147, 22.0162952], [112.2777142, 22.0162654], [112.2777091, 22.0162184], [112.2777293, 22.0155411], [112.2777934, 22.016181], [112.277763, 22.0163602], [112.2777463, 22.0162394], [112.2777951, 22.0166046], [112.2776927, 22.0162132], [112.2777378, 22.0165474], [112.2775909, 22.0162195], [112.2775837, 22.0163702], [112.2773571, 22.0163615], [112.2774887, 22.0162945], [112.2779636, 22.0155648], [112.2776821, 22.0153425], [112.2775655, 22.01528], [112.277327, 22.0165847], [112.2776053, 22.0159045], [112.2776661, 22.0159655], [112.2777093, 22.0158935], [112.2777605, 22.0160012], [112.2774871, 22.0163442], [112.2775043, 22.0159103], [112.2774271, 22.0161922], [112.2775719, 22.0157997], [112.2779507, 22.0161869], [112.2772691, 22.0158395], [112.2774603, 22.0160507], [112.2773284, 22.0161886], [112.2769806, 22.0162803], [112.277367, 22.0160714], [112.2774255, 22.0156315], [112.2773364, 22.0165652], [112.2779057, 22.0172664], [112.2773697, 22.0159611], [112.2775842, 22.0168184], [112.2771331, 22.0168276], [112.276935, 22.0170211], [112.2771452, 22.0167653], [112.2772963, 22.0167357], [112.2773487, 22.016833], [112.2771117, 22.0170429], [112.2772882, 22.0150137], [112.277676, 22.0157572], [112.2775809, 22.0157616], [112.2776087, 22.0151958], [112.2775472, 22.0157747], [112.2776357, 22.0154047], [112.2776435, 22.0164565], [112.2776643, 22.0169043], [112.2764386, 22.0158418], [112.2777676, 22.016478], [112.2777093, 22.0165748], [112.2777221, 22.016404], [112.2775944, 22.0157735], [112.2777799, 22.0157752], [112.2776128, 22.0154483], [112.2777016, 22.0151869], [112.2775887, 22.0153978], [112.2775413, 22.0154168], [112.2776436, 22.0155891], [112.277575, 22.0155052], [112.2776914, 22.0161053], [112.2774094, 22.0156116], [112.2773298, 22.0158133], [112.2773486, 22.0160223], [112.2773499, 22.0160166], [112.2773534, 22.0160091], [112.2773868, 22.01594], [112.2776449, 22.0154259], [112.2775975, 22.016411], [112.2777683, 22.0155985], [112.2777066, 22.0155994], [112.2776718, 22.0156146], [112.2776693, 22.0156116], [112.2776541, 22.0155184], [112.2776593, 22.0160912], [112.277661, 22.016092], [112.2778694, 22.0157039], [112.2779937, 22.0157449], [112.2777242, 22.0159336], [112.2777495, 22.016103], [112.2774126, 22.0164878], [112.2774447, 22.0164391], [112.2774575, 22.0164354], [112.2775494, 22.0164708], [112.2777794, 22.0165267], [112.2775416, 22.0161283], [112.2774464, 22.0163779], [112.2778153, 22.0165429], [112.2776616, 22.0162139], [112.2774604, 22.0162103], [112.2776942, 22.0160659], [112.2775707, 22.0163708], [112.2774991, 22.0160763], [112.2774355, 22.0162447], [112.2776771, 22.0160008], [112.2776718, 22.0160062], [112.277704, 22.015915], [112.2777063, 22.0159108], [112.2775323, 22.0164836], [112.2777955, 22.0167154], [112.2778581, 22.0175943], [112.2776463, 22.0159604], [112.27762, 22.0163717], [112.2775426, 22.0163401], [112.2775736, 22.0157782], [112.2776664, 22.0157741], [112.2776853, 22.0163118], [112.2777307, 22.0162768], [112.2775162, 22.0161832], [112.2776874, 22.0162421]]
            }
        }

when I use turf.lineSliceAlong(route,8.461539655960873,8.478462735272794,, {units: 'kilometers'})
There will have a mistake,
(Uncaught Error: coordinates must contain number).
Code return lineString(coords[coords.length - 1]) as a point ,but the point could not be a linestring

@dpmcmlxxvi
Copy link
Collaborator

@tpolong Looks like a bug. There's an edge case here. If the start point is exactly on the end point of the line, the line-slice-along function is attempting to return a line with only one point. There are two issues:

  • A LineString must be two or more points.
  • The helper function turf.lineString is being called with a coordinate instead of an array of coordinates.

The code fix is to either return a LineString with the end point repeated (the spec is unclear if this is a valid line) or disallow this case. I think the first is fine.

In the meantime, you can test for this condition by checking the turf.length(route) < startDist before calling slice.

@tpolong
Copy link
Author

tpolong commented Jun 9, 2019

@dpmcmlxxvi The turf.linechunk function also uses the line-slice-along function ,but it doesn't test for this condition by checking the turf.length(route) < startDist before calling slice.( in the sliceLineSegments function )

@dpmcmlxxvi
Copy link
Collaborator

@tpolong It doesn't look like the turf.lineChunk needs to test for that condition. The line is divided into segments of equal length, so the starting point can't be on the line's end-point.

@tpolong
Copy link
Author

tpolong commented Jun 9, 2019

@dpmcmlxxvi var route = {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[70.2998991, 20.0126324], [70.2996097, 20.0134472], [70.2996597, 20.0133881], [70.2777231, 20.0164887], [70.2774728, 20.0166772], [70.2774033, 20.0165736], [70.2775611, 20.0164055], [70.2776283, 20.0161038], [70.2776846, 20.0163612], [70.2776739, 20.0163395], [70.2776479, 20.0163987], [70.2776427, 20.0162798], [70.2775763, 20.016116], [70.2777209, 20.0161367], [70.2777592, 20.0161772], [70.2777634, 20.0162569], [70.277711, 20.0162028], [70.2776429, 20.0159677], [70.2777159, 20.0164053], [70.2777012, 20.0164482], [70.2777467, 20.0159461], [70.2774918, 20.016208], [70.2777323, 20.0163755], [70.27788, 20.0156734], [70.2777364, 20.0161047], [70.2777321, 20.0154175], [70.2775976, 20.0159372], [70.2775141, 20.0164520], [70.2773987, 20.0163157], [70.2777456, 20.016317], [70.2777335, 20.0160323], [70.2776058, 20.0159735], [70.2776119, 20.0162441], [70.277613, 20.0162797], [70.2776901, 20.0159297], [70.2776718, 20.0159579], [70.2776664, 20.0160062], [70.2776555, 20.0160424], [70.2776820, 20.0163974], [70.2776653, 20.0165653], [70.277671, 20.0165485], [70.2776557, 20.0165534], [70.2776157, 20.0157634], [70.2777147, 20.0160169], [70.2777923, 20.0161012], [70.2777863, 20.0160907], [70.2777051, 20.016329], [70.2777147, 20.0162952], [70.2777142, 20.0162654], [70.2777091, 20.0162184], [70.2777293, 20.0155411], [70.2777934, 20.016181], [70.277763, 20.0163602], [70.2777463, 20.0162394], [70.2777951, 20.0166046], [70.2776927, 20.0162132], [70.2777378, 20.0165474], [70.2775909, 20.0162195], [70.2775837, 20.0163702], [70.2773571, 20.0163615], [70.2774887, 20.0162945], [70.2779636, 20.0155648], [70.2776821, 20.0153425], [70.2775655, 20.01528], [70.277327, 20.0165847], [70.2776053, 20.0159045], [70.2776661, 20.0159655], [70.2777093, 20.0158935], [70.2777605, 20.0160012], [70.2774871, 20.0163442], [70.2775043, 20.0159103], [70.2774271, 20.0161920], [70.2775719, 20.0157997], [70.2779507, 20.0161869], [70.2772691, 20.0158395], [70.2774603, 20.0160507], [70.2773284, 20.0161886], [70.2769806, 20.0162803], [70.277367, 20.0160714], [70.2774255, 20.0156315], [70.2773364, 20.0165652], [70.2779057, 20.0172664], [70.2773697, 20.0159611], [70.2775842, 20.0168184], [70.2771331, 20.0168276], [70.276935, 20.0170211], [70.2771452, 20.0167653], [70.2772963, 20.0167357], [70.2773487, 20.016833], [70.2771117, 20.0170429], [70.2772882, 20.0150137], [70.277676, 20.0157572], [70.2775809, 20.0157616], [70.2776087, 20.0151958], [70.2775472, 20.0157747], [70.2776357, 20.0154047], [70.2776435, 20.0164565], [70.2776643, 20.0169043], [70.2764386, 20.0158418], [70.2777676, 20.016478], [70.2777093, 20.0165748], [70.2777201, 20.016404], [70.2775944, 20.0157735], [70.2777799, 20.0157752], [70.2776128, 20.0154483], [70.2777016, 20.0151869], [70.2775887, 20.0153978], [70.2775413, 20.0154168], [70.2776436, 20.0155891], [70.277575, 20.0155052], [70.2776914, 20.0161053], [70.2774094, 20.0156116], [70.2773298, 20.0158133], [70.2773486, 20.0160203], [70.2773499, 20.0160166], [70.2773534, 20.0160091], [70.2773868, 20.01594], [70.2776449, 20.0154259], [70.2775975, 20.016411], [70.2777683, 20.0155985], [70.2777066, 20.0155994], [70.2776718, 20.0156146], [70.2776693, 20.0156116], [70.2776541, 20.0155184], [70.2776593, 20.0160912], [70.277661, 20.016092], [70.2778694, 20.0157039], [70.2779937, 20.0157449], [70.2777242, 20.0159336], [70.2777495, 20.016103], [70.2774126, 20.0164878], [70.2774447, 20.0164391], [70.2774575, 20.0164354], [70.2775494, 20.0164708], [70.2777794, 20.0165267], [70.2775416, 20.0161283], [70.2774464, 20.0163779], [70.2778153, 20.0165429], [70.2776616, 20.0162139], [70.2774604, 20.0162103], [70.2776942, 20.0160659], [70.2775707, 20.0163708], [70.2774991, 20.0160763], [70.2774355, 20.0162447], [70.2776771, 20.0160008], [70.2776718, 20.0160062], [70.277704, 20.015915], [70.2777063, 20.0159108], [70.2775323, 20.0164836], [70.2777955, 20.0167154], [70.2778581, 20.0175943], [70.2776463, 20.0159604], [70.27762, 20.0163717], [70.2775426, 20.0163401], [70.2775736, 20.0157782], [70.2776664, 20.0157741], [70.2776853, 20.0163118], [70.2777307, 20.0162768], [70.2775162, 20.0161832], [70.2776874, 20.0162421]]
}
}

    var lineDistance = turf.lineDistance(route, { units: 'kilometers' });
var nstep = 500;
    var nDistance = lineDistance / nstep;
var chunk = turf.lineChunk(route ,nDistance, {units: 'kilometers'})

If numberOfSegments is integer, no need to plus 1.In the case numberOfSegments pluses 1,so the code will have errors

@dpmcmlxxvi
Copy link
Collaborator

@tpolong This looks like a different bug due numerical precision. Please submit as a different issue.

@dpmcmlxxvi
Copy link
Collaborator

Looks like a duplicate of #1577

@tpolong tpolong closed this as completed Jul 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants