7

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

  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Question and Answer format. What have you tried? Did the post for ArcGIS give any suggestions that look like they might work with QGIS? Please edit your question to include any extra information. – Midavalo Jan 20 '17 at 0:37
9

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.

  • Precision I'm assuming relates to distance between features, note the dialog is quite different as of QGIS 2.18, setting required are: geometric predicate = intersect, precision = max distance collisions are from road line, statistics for summary = sum and joined table = only keep matching records – George of all trades Jan 20 '17 at 10:33
  • Thanks for this - I edited to clarify that the points are not exactly snapped to the lines. Maybe I just need to experiment with using the precision setting to capture all of the collisions. – Logan Jan 20 '17 at 21:15
  • In the more recent versions (I'm using 2.18.13) you have to specify precision - just set this to 1 as would be used in this example. I created a small buffer around the point and this worked - similar type of data -> collisions / segment of road. – Mark Thompson Oct 28 '18 at 5:59
  • In QGIS 3 you need to go to the processing toolbar to open the Join attributes by location (summary) tool. – Mark Thompson Mar 6 at 17:37

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.