[GIS] Count number of points per line in QGIS

qgis

I have a line shapefile of roads and a point shapefile of car collisions, and am trying to count the number of collisions per road. The points do not exactly intersect with the lines. I'm hoping to end up with a new column in the "roads" attribute table with the number of collisions. I've found a post on how to do that in ArcGIS here: How to produce a 'count' of points intersecting lines?, but haven't been able to figure it out in QGIS.

I've found suggestions to create a buffer of the roads in order to create a polygon and use the Points in Polygon analysis, but the roads data is quite large and creating a buffer was taking ages for me, so I'm hoping there's another option. I've tried using the "Join attributes by location" function, with "roads" as the target layer and "collisions" as the join layer, but I don't know how to set the Precision input so that all of the collision points are counted. In Arc "Join based on spatial location" has "closest" option when joining points to lines, and I'm hoping that QGIS offers something comparable.

I'm using QGIS 2.18.2

Best Answer

You can use Join by location to join polyline with point shapefiles. However, the point should be exactly snapped to the line in order to be joined, otherwise, it is better to create a buffer of polygon shapefile around the road lines of distance that you can decide after several tests, then use the buffered polygon to join the points by location. To find the tool, you can go to Vector -> Data management tools -> Join by location, as you can see below:

enter image description here

The output polygon will create a count field in the attribute table of the number of accident points:

enter image description here

I used QGIS 2.14.8 for the above process.

Related Question