1

I am new to GIS, know really nothing about coding or GIS. I am using QGIS 3.6.2, for which is it apparently hard to find up-to-date user guides.

I have made a map that includes road files and site locations. I added points along the road to be able to find the closest points on the road to the sites. I got an output that gives me the closest points and their distances, but cannot figure out how to get a line between these two sets of points. The ultimate goal is to be able to determine distances between sites using these roads.

enter image description hereenter image description here

jsilverman
  • 87
  • 8
  • If you want to find the distance between points via the road network look for routing tools. This two blog posts might be a good place to start: https://www.qgistutorials.com/en/docs/3/basic_network_analysis.html and https://anitagraser.com/2019/07/07/five-qgis-network-analysis-toolboxes-for-routing-and-isochrones/ – ycartwhelen Jul 06 '21 at 12:49
  • Before I can use routing tools, I need to add the existing road network by connecting it to the sites. It is this connections, from nearest points on the road to the sites that I cannot figure out. I have a list of distances for each, but I cannot get that information to translate into lines. – jsilverman Jul 06 '21 at 12:54
  • Take a look at snapping points to a line https://gis.stackexchange.com/questions/237224/aligning-multiple-points-to-line-in-qgis – ycartwhelen Jul 06 '21 at 13:42
  • Thanks, but that is not what I am trying to do. I want to create new lines, that run from points to the points that were identified as the closest points on the existing lines (road shape file). The result would be brand new lines between the existing line to the points. This should be theoretically possible, as the distance to nearest point on line algorithm selects a point on the existing line. All I want is instead of just calculating the distance is to create a new line between those points. – jsilverman Jul 07 '21 at 07:37
  • I added a solution to create the lines you want. However, routing should work from the snapped points on the line as well - that's why it is unclear to me as well why you need this line - and for what. – Babel Jul 07 '21 at 08:39
  • It worked. I wanted the lines for two reasons: visualization purposes (this is for research presentations and publications) and to verify that it is calculating from the right bases. (This proved necessary, as the first few times I ran your code, all the sites linked to one random point and not the line, so the visualization let me easily confirm when I finally did it correctly). – jsilverman Jul 07 '21 at 12:17

1 Answers1

1

Let's say you have a line layer called line and a point layer called points. To connect to points to the closest point on the line, use Menu Processing / Toolbox /& Geometry by expression (see documentation), set points as Input layer, select line for Output geometry type and insert this expression:

make_line (
    $geometry,  
    closest_point( 
        aggregate (
            'line', 
            'collect',
            $geometry
        ),
        $geometry
    )
)

Using the expression, here with geometryx generator for visualization purpose: enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208