6

When I use the "Line Intersections" tool in QGIS, it doesn't create whole intersect points. Also, the gif and picture below show that the lines intersect but the plugin doesn't assign any point to them. How can I solve the problem?

enter image description here

enter image description here

7
  • The geometries, you think they are two separate lines, may be one polyline. If it is, the tool doesn't generate intersection points for the lines within the same geometry, even if it contains an intersection. Oct 12 at 12:39
  • 3
    Select the line(s), if it is one geometry, then you should split it and run the tool again. Otherwise, the lines probably do not touch. Oct 12 at 12:45
  • 1
    This line, which is inside the circle is not the polyline. Also, when we use the v.clean tool in QGIS, the same situation happened and there is no problem with snapping. Oct 12 at 13:48
  • If they dont touch, take a look at "Extend lines" or "Snap geometries to layer" from processing toolbox.
    – MrXsquared
    Oct 12 at 14:55
  • 2
    Did you run the check validity tool by any chance? I always do if a tool fails to work as expected since it is quick and easy.
    – johns
    Oct 12 at 16:36
4

This is a very common issue in GIS. In the case of your data, it occurs because the vertical line doesn't have a node that matches the final point of the diagonal line, and due to geometric non-robustness, the geometry engine fails finding an intersection there.

Solution

You need to make sure the layer has a proper topology before running the Line intersections algorithm (it means, either modify your original layer or run the Line intersections over a modified copy of your original layer). In practice, just follow these steps:

  1. Run the Snap Geometries to Layer with the following parameters:

    enter image description here

    Same input and reference layers. The tolerance is up to you, but a tolerance of 1 mm. works well for most cases (planar coordinates). Regarding the behavior, you can choose the second option, called Prefer closest point, insert extra vertices where required (it's important to choose one that inserts vertices).

  2. Run the Line intersections algorithm using the output of the step 1.

And that's it. Doing that you'll get the point intersections you expect.

enter image description here


Tip

I suggest you to build a model like the following, so that you get what you want in one go. Anyway, you'll probably need to remove the duplicated intersections the Line intersections returns.

enter image description here


Note 1: The Snap Geometries to Layer algorithm has been heavily optimized and adjusted lately (see https://github.com/qgis/QGIS/pull/42781 and https://twitter.com/GeoTux2/status/1435136250487480320). So, you need to use QGIS >= v3.21.x. QGIS 3.22.0 will be released in 9 days, but you can download a nightly build if you cannot wait until then.

Note 2: Fortunately, GEOS v3.9 solves this issue of geometric non-robustness. Therefore, as soon as QGIS upgrades GEOS to v3.9, we'll be able to see the expected results without intermediate steps (like running Snap Geometries to Layer). Since these thing don't happen automatically, you could get involved in the project. Sometimes an effort from the community itself is needed before such changes happen (e.g., via funding).

3
  • Could you elaborate a bit on the robustness aspect? Basically, it is due to a rounding issue that snapping does not always work as expected, is that correct?
    – Babel
    Oct 14 at 7:17
  • I tried your solution with the dataset provided by OP. I used the very settings you propose for the 'Snap Geometries to Layer' tool, however, line intersection on the modified layer still doesn't find all intersecting points. I increased tolerance to 1 m, still with the same result. Using QGIS 3.20.0 with GEOS 3.9.1-CAPI-1.14.2. Using the extend line solution works with OP's (unprocessed) dataset, even the simple intersection operation with QGIS expression works, without extending the lines.
    – Babel
    Oct 14 at 7:41
  • @Babel, the answer says that you need to use at least QGIS 3.21 (dev version). Yes, that's also something I explained in the answer, GEOS 3.9 solves the issue, see Note 2. Oct 14 at 12:50
4

Probably in the cases where you don't get an intersection, probably the lines do not touch or there is a snapping issue like this one. There's probably a (very tiny) gap- so small you don't see it. The solution is to make the lines a tiny bit longer: to extend it using QGIS expression extend.

You can test it by applying an additional Geometry generator symbol layer, rendering as point and using this expression:

intersection(
    $geometry,  
    difference(
        collect($geometry),
        $geometry
        )
    )

Than change this expression by replacing $geometry in line two by this: extend ($geometry, 0.1, 0.1). With this, you make your lines a tiny bit longer (by 0.1 map units - change this value if needed). In this case, you get additional intersection points where the initial lines do not touch. When satisfied with the result, you can convert it to actual geometries (new layer) using Geometry by expression with the same expression. Run Multipart to single parts on the result.

Left: one line does not intersect the others (red circle); Right: with the revised expression, you also get a point there: enter image description here

5
  • 2
    I used the snapping tool and also I checked the intersection without point there is no problem with snapping. I zoomed enough. I applied your solution. It generates some points but also line intersection tool generates them. Your solution does not generate any point that. line intersection tool does not generate too. Oct 12 at 14:07
  • 2
    Can you share your data (or a sample of it), containing the problematic spots?
    – Babel
    Oct 12 at 14:16
  • github.com/aycatbkoglu/QGIS-Intersection-tool-error-dataset our dataset is in the repo Oct 13 at 14:08
  • I downloaded your files and applied the first expression from my answer (without extend_line): all intersections show correctly, see: i.stack.imgur.com/kjnue.png - did you try this solution? It should return all intersection points correctly
    – Babel
    Oct 13 at 18:37
  • Line intersection tool indeed does not generate all points, even if they seem to be snapped. However, QGIS seems to have a snapping problem sometimes, see this: gis.stackexchange.com/a/379655/88814 . The solution here is to extend the lines a little bit: with that, even the Line interesection tool creates all correct points.
    – Babel
    Oct 13 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.