2

I have GeoJSON multipoint layer and would like to create a line network (GeoJSON multiline) out of it. Best case the points would be snapped to a road. I have only coordinates and no additional information for these points.

enter image description here

I've tried to use QGIS "Points to path" tool, but i have no order for the points, so that's not really the result I'm looking for.

I think the steps would be something like this:

  • Remove points that are close to each other
  • Extract street layer from OSM
  • Snap points to streets
  • Connect closest points

I don't really know where to start and what tools to use for this.

1
  • 1
    Is there a specific reason why you dont go the simple way of downloading streets from OSM and keeping only those within a certain distance to one of your points? Because creating a line network out of points with no informations can be a real pain with lots of manual work required to fix wrong connections. Especially when there are "point bubbles" as in your screenshot.
    – MrXsquared
    Dec 15 '20 at 15:05
2

Depending on where you have your data from, there should be some information that allows to connect the points in a certain order. If you really have only the geometry (points) with no further information, you can try the follwowing - it's not perfect, but if your points are near enough, the solution should be satisfying, maybe needs some manual adjusting:

Menu Processing / Toolbox / Join attributes by nearest (1 and 2 on the screenshot below). Select twice your points as input layer and set Maximum nearest neighbors to 2. Run the tool and you get the same points as output in a new layer (3), but containing additional attributes: distance, feature_x, feature_y, nearest_x, nearest_y. So for every point, you get it's coordinates as well as the coordinates for the nearest neighboring point. In fact, you get two points for each input point, as we defined to create the 2 nearest neighbors.

You can use this information to create a line with QGIS expressions - either as new symbol layer with geometry genarator (for visualization purpose only) or by using the tool geometry by expression (from the toolbox) to creat an actual line.

In the screenshot, you see the resulting line using a new symbol layer (4), set it to geometry generator, geometry type line and use this expression (5):

make_line ( make_point ( "feature_x" ,  "feature_y" ) , make_point ( "nearest_x" , "nearest_y" ) )

This creates the blue line you see on the screenshot that connects the red points.

If you want to create an actual geometry, paste the same expression to the geometry by expression tool.

enter image description here

2

A completely different way is to snap the points to an existing street-layer, e.g. from OpenStreetMap, as you suggest. You can use QGIS expressions to create geometries - either as symbol layer or with geometry by expression, as described above.

  1. Use this expression to create a new point layer, using geometry by expression with the original points as input - replace the 4 instance of highway with the name of your street layer (and maybe adapt the numbers of 0.000001, but it should work like this):

     intersection( 
         extend ( 
             ( make_line ( 
                 $geometry,
                     closest_point (
                         geometry ( 
                             get_feature_by_id (
                             'highway',   
                             array_to_string ( 
                                 overlay_nearest ( 
                                     'highway',  $id )
                                 )
                         )
                     ) ,
             $geometry )
             )
         ), 
     0.000001 , 0.000001
     ),
     collect_geometries (
         array_foreach ( 
             generate_series (
                 1,  
                 aggregate 
                     ( 'highway', 'count', $id)
             ),
             geometry (
                 get_feature_by_id (
                     'highway', @element
                 )
             )
         )
     )
    

    )

This creates for each input-point (red) a new point on the nearest point of the street layer (white), thus "snapping" to it.

enter image description here

  1. Now you can use the tool Menu Processing / Toolbox / Shortest path (layer to point) and set the network (OSM streets) as Vector layer representing network and the points created before as Vector layer with start points. For Path type to calculate select shortest. Then select an end point - use snapping and click somewhere on the network (streets) layer where the connecting lines should pass through. Than run the tool.

On the next screenshot, you see the settings: blue: input points (the points snapped to the network in step 1); green: street network from OpenStreetMap; red: output: lines connecting the blue points using the green network.

enter image description here

As this algorithm creates a connection from each input point to the destination point selected, you get a lot of overlapping (duplicate) lines you may want to delete. You can do this using a combination of first explode lines and than Delete duplicate geometries. Both tools can be accessed via Menu Processing / Toolbox.

Be also aware of the fact that each point connects to the same destination points and paths are thus calculated with respect to the shortest connection to this destination. That also means that sometimes, nearby points are not connected - you can see an example exactely below the red rectangle in the screenshot above.

Depending on what you want to use the created line for, you could also use a combination of this solution here and the previously proposed solution (using this time the snapped points as input for Join attributes by nearest). Than you can buffer both results and use Menu Vector / Geoprocessing Tools / Difference to see where there are major differences of both solution (filter the result of the difference tool for a minimal area to get only major differences). These places are possible spots where a manual improvement is needed.

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.