I use QGIS 2.18 and I have a point shapefile of many animal locations and a shapefile of roads.

I want to use QGIS to tell me how many roads are between each pair of animal locations.

So, basically how many roads would they have to cross to get to the other point.

  • 2
    Connect each pair of points with a line. Then it should be easy to count the number of roads each line intersects, eg by using the intersecting_geom_count() function. – csk Mar 14 at 21:36
  • 1
    Do u intend to check all animal locations pairs or narrow down a bit your search ? What is the complexity of your dataset ? – snaileater Mar 15 at 8:39
  • I am looking at all pair-wise comparisons. I have 64 individuals. – Christy Pruett Mar 26 at 18:15

In Database / Database Manager / Database Manager then Virtual Layers / Qgis Layers you can try the following query to create your line layer :

select a.id, b.id, make_line(st_centroid(a.geometry),st_centroid(b.geometry)) as line from animal_locations a, animal_locations b
where a.id>b.id

you save the result (Care about the size of your dataset) ...

Then, as @csk indicated, you edit this layer by adding a virtual field using the following expression :


RefFunction plug-in required to access this expression ... And you should have the answer you're seeking.

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.