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?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
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.
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.
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:
Snap Geometries to Layer with the following parameters:
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).
Line intersections algorithm using the output of the step 1.
And that's it. Doing that you'll get the point intersections you expect.
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.
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).