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

lineSplit does not split a lineString if splitter is very close to a vertex point #852

Closed
grundid opened this issue Jul 20, 2017 · 10 comments
Assignees
Labels
Milestone

Comments

@grundid
Copy link
Contributor

grundid commented Jul 20, 2017

The following test returns a feature collection with only one element.
I would expect two elements.

const lineString = turf.lineString([[9.2202022, 49.1438226], [9.2199531, 49.1439048], [9.2196177, 49.1440264]]);
const resultFc = turf.lineSplit(lineString, turf.point([9.219953175634146, 49.14390480825327]));
t.equals(resultFc.features.length, 2);

When I reduce the precision of the splitter the result is correct:

const lineString = turf.lineString([[9.2202022, 49.1438226], [9.2199531, 49.1439048], [9.2196177, 49.1440264]]);
const resultFc = turf.lineSplit(lineString, turf.point([9.2199531, 49.1439048]));
t.equals(resultFc.features.length, 2);
@stebogit
Copy link
Collaborator

@grundid it seems to be a matter of decimals in the splitter (point) coordinates:

const lineString = turf.lineString([[9.2202022, 49.1438226], [9.2199531, 49.1439048], [9.2196177, 49.1440264]]);
const resultFc = turf.lineSplit(lineString, turf.point([9.219953, 49.143905])); // coordinates truncated to 6 decimals
//={ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "LineString", "coordinates": [ [ 9.2202022, 49.1438226 ], [ 9.2199531, 49.1439048 ], [ 9.219953, 49.143905 ] ] } }, { "type": "Feature", "properties": {}, "geometry": { "type": "LineString", "coordinates": [ [ 9.219953, 49.143905 ], [ 9.2196177, 49.1440264 ] ] } } ] }

Turf follows GeoJSON recommendations by using 6 decimals to define coordinates.

@DenisCarriere we might want to truncate the coords of the splitter in@turf/line-split to avoid this issue?

@grundid
Copy link
Contributor Author

grundid commented Jul 20, 2017

If Turf follows the GeoJSON recommendations then maybe turf.point should not create a GeoJSON object with to many decimals. ;)

@DenisCarriere
Copy link
Member

DenisCarriere commented Jul 20, 2017

then maybe turf.point should not create a GeoJSON object with to many decimals

Might not be a good idea to add truncate to turf.point since that would add unnecessary overhead if it's not required.

we might want to truncate the coords of the splitter in@turf/line-split to avoid this issue?

👍 Agreed, for this scenario we might want to introduce truncate for the splitter, we can add this exact example to the test.js.

@grundid Good catch!

@DenisCarriere DenisCarriere added this to the 4.6.0 milestone Jul 20, 2017
stebogit added a commit that referenced this issue Jul 21, 2017
- applied truncate on splitter;
- added throw tests;
- updated feature test results and bench;
DenisCarriere added a commit that referenced this issue Jul 21, 2017
@DenisCarriere
Copy link
Member

Fixed in the next minor release.

@grundid
Copy link
Contributor Author

grundid commented Aug 4, 2017

After the latest release lineSplit became somehow quite useless for my cases:

Case 1:

  const lineString = turf.lineString([[9.2202022, 49.1438226], [9.2199531, 49.1439048], [9.2196177, 49.1440264]]);
  const resultFc = turf.lineSplit(lineString, turf.point([9.2202022, 49.1438226]));

Returns two lines. One very short:
line1: [[9.2202022,49.1438226],[9.220202,49.143823]]
line2: [[9.220202,49.143823],[9.2199531,49.1439048],[9.2196177,49.1440264]]
Expected result would be to not cut at all.

Case 2:

  const lineString = turf.lineString([[9.2185956, 49.1450893], [9.2181343, 49.1443734], [9.2192501, 49.1438962]]);
  const resultFc = turf.lineSplit(lineString, turf.point([9.2181343, 49.1443734]));

Here the cut does not work. lineSplit returns one feature which is the original line.

@DenisCarriere
Copy link
Member

@grundid Thanks for reporting this, could you add these test cases to the turf-line-split/test.js with your expected results, the PR should fail.

grundid added a commit to geohub-plattform/turf that referenced this issue Aug 7, 2017
@stebogit
Copy link
Collaborator

stebogit commented Aug 8, 2017

Bug still somewhere... 🐛
See PR #892

@stebogit stebogit reopened this Aug 8, 2017
@DenisCarriere
Copy link
Member

Those pesky 🐛 🐞 !

DenisCarriere added a commit that referenced this issue Aug 11, 2017
@DenisCarriere DenisCarriere modified the milestones: 4.7.0, 4.6.0 Aug 11, 2017
@DenisCarriere
Copy link
Member

This is fixed in the latest @turf/line-split@4.6.1

@IshanthaKamal
Copy link

IshanthaKamal commented Apr 4, 2018

Scenario 1

3

Expected Result

2

Scenario 2

1

I was trying to get split parts of 2 lines and get the merge.What I did was get line split in line1 vs line2 and again line2 vs line1. Issue is line splitting not working properly when splitting is close to vertex point as in above images.I noticed that line split is not giving proper splitter parts.In last scenario line splitting is giving only 2 splitter parts of line A instead of 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants