Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lineOverlap tolerance is not handled in every case

jsiedentop opened this issue · comments

The current implementation splits thepassed features into lineStrings. Then, for each segment in feature2, rbush is used to search whether there are overlapping points to a segment from feature1. In principle, at least one point must lie within the bounding box of a feature1 segment. The bug is, that the tolerance parameter passed is not taken into account here.

Even if two segments are very close to each other and run parallel, no overlapping would be detected even if a generous tolerance value was selected.

In TurfDart, I have chosen the approach of increasing the bounding box by the tolerance. This allows us to find all segments that lie within the specified tolerance. For details see: line_overlap.dart

In this example, I have two LineStrings that run parallel to each other. The distance is 11.4km and if you pass a tolerance of 12km, I think lineOverlap should return a result. Admittedly the distance is quite long, the example is for demonstration purposes and also works at distances of a few meters.

image

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "stroke": "#0F0",
        "fill": "#0F0",
        "stroke-width": 25
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            10,
            0
          ],
          [
            11,
            0
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "stroke": "#F00",
        "fill": "#F00",
        "stroke-width": 10,
        "stroke-opacity": 1,
        "fill-opacity": 0.1
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            10,
            0.1
          ],
          [
            11,
            0.1
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "stroke": "#00F",
        "fill": "#00F",
        "stroke-width": 3,
        "stroke-opacity": 1,
        "fill-opacity": 0.1
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            10,
            0
          ],
          [
            11,
            0
          ]
        ]
      }
    }
  ]
}