I am new to QGIS.

I have two layers (layer_a and layer_b) consisting of two sets of points.

If I want to find the nearest point in layer_b for each point in layer_a, I can just use the Distance matrix calculator that comes with the graphical interface in QGIS.

My issue is slightly more complicated. I want to group both layers by an attribute value, before I calculate the distance between points.

Translation: if layer_a has a bunch of points to libraries around the world and layer_b has a bunch of points to big cities around the world, and both layers have an attribute where the value tells me which country each point is in, then I want to find the shortest distance between a library point in a specific country and a big city point in the same country.

I could accomplish this by splitting the layers by country and then repeating the analysis on each layer (i.e. distance between library points in Germany and big city points in Germany), using the graphical interface in QGIS, but this is tedious. Also, in reality I will have thousands of groups.

How do I do this in QGIS?

  • 1
    Welcome to GIS SE! We're a little different from other sites. We're a Q&A site, not a discussion forum. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. Please check out our short tour for more about how the site works. Thanks. – PolyGeo Jun 20 '19 at 7:52
  • 1
    If you are looking for a PyQGIS solution then ask that in a separate question. – PolyGeo Jun 20 '19 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.