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

splitLineWithPoints doesn't split correctly #2604

Closed
kudlav opened this issue May 7, 2024 · 2 comments
Closed

splitLineWithPoints doesn't split correctly #2604

kudlav opened this issue May 7, 2024 · 2 comments

Comments

@kudlav
Copy link
Contributor

kudlav commented May 7, 2024

turf.lineSplit is not splitting properly large geometries, even after removing the square as suggested in #1232.

I have two cases. The first is on a scale of 1:100, and the second is 1:1 (original). For the first one, it returns 5 segments (correct), for the second one only 4 of 5 segments.

// 1:100
turf.lineSplit(
  {
    type: 'Feature',
    properties: {},
    geometry: {
      type: 'LineString',
      coordinates: [[14.14, 42.24], [9.92, 34.4], [11.44, 29.92], [9.76, 28.48], [1.44, 29.9], [-13.28, 27.04], [-34.04, 14.88], [-31.64, 7.2], [-22.56, 10.8], [-3.68, 4.1], [-6.22, -9.44], [-3.36, -12.2], [23.84, -11.02], [31.84, -6.7], [42.24, -7.5]],
    },
  },
  {
    type: 'Feature',
    properties: {},
    geometry: {
      type: 'Polygon',
      coordinates: [[[0, 0], [40.96, 0], [40.96, 18.62], [15.68, 5.16], [5.56, 27.7], [20.77, 35.69], [0, 40.96], [0, 0]]],
    },
  },
);

// 1:1
turf.lineSplit(
  {
    type: 'Feature',
    properties: {},
    geometry: {
      type: 'LineString',
      coordinates: [[1414, 4224], [992, 3440], [1144, 2992], [976, 2848], [144, 2990], [-1328, 2704], [-3404, 1488], [-3164, 720], [-2256, 1080], [-368, 410], [-622, -944], [-336, -1220], [2384, -1102], [3184, -670], [4224, -750]],
    },
  },
  {
    type: 'Feature',
    properties: {},
    geometry: {
      type: 'Polygon',
      coordinates: [[[0, 0], [4096, 0], [4096, 1862], [1568, 516], [556, 2770], [2077, 3569], [0, 4096], [0, 0]]],
    },
  },
);

The problem is in splitLineWithPoints function.
It gets correctly the same 4 intersections, the splitter parameter is:

// 1:100
[0, 29.62021739130434]
[7.710658597785979, 28.82976740278172]
[11.189808184780334, 30.657407455384277]
[11.834699005058457, 37.957165924089644]

// 1:1
[0, 2962.021739130435] }
[771.0658597785978, 2882.976740278172]
[1118.9808184780334, 3065.7407455384277]
[1183.4699005058458, 3795.7165924089645]

This code doesn't check if the closestLine was actually split into two lines. And, in my second case, when splitLineWithPoint splitting using point [771.0658597785978, 2882.976740278172], the splitLineWithPoint returns only one line instead of twos (the splitting or choosing the closestLine is broken).

// Append the two newly split lines into the results
featureEach(splitLineWithPoint(closestLine, point), function (line) {
results.push(line);
tree.insert(line);
});

image

@turf/turf v7.0.0-alpha.115
Node.js v20.11.1

@smallsaucepan
Copy link
Member

smallsaucepan commented May 7, 2024

Thanks for the detailed write up @kudlav. For the second example (which returns an incorrect result) I noticed the co-ordinates are outside what would typically be expected as valid geojson for Turf:

type: 'LineString',
      coordinates: [[1414, 4224], [992, 3440], [1144, 2992], ...

[lng, lat] respectively would typically be -180 to +180, and -90 to +90 decimal degrees. Can you run through your use case in more depth if those are the values you need to use? What is the significance of the scaling?

@kudlav
Copy link
Contributor Author

kudlav commented May 9, 2024

Hi, you are right. I'm working out of WGS84 range. Other turf functions are fine with it. I'll normalize our range into WGS84 before using the splitLineWithPoints as a workaround.

@kudlav kudlav closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants