11

I am looking for a possibility to make a one-to-many table-join in QGIS.

I have a shapefile with postal codes and would like to join them with survey results (more than one). In other words, there is a specific postal code (shapefile) on one side and there are many survey participants on the other side.

postal **code1** ----- survey participant **1**
postal **code1** ----- survey participant **2**
postal **code1** ----- survey participant **3**
postal **code2** ----- survey participant **1**
postal **code2** ----- survey participant **2**
and so on ...

If I do a normal join (right click on Layer --> Properties --> Join) , I just get the first entry of the table with the postal codes.

I found out a way to do it ArcGIS with the tool "Make Query Table", but I´m looking for a possibility to do it in QGIS.

Taras
  • 32,823
  • 4
  • 66
  • 137
MTwain
  • 111
  • 1
  • 1
  • 6
  • Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our [faq]. – underdark Jul 26 '15 at 11:03

2 Answers2

6

Depending on what exactly you want to do, you can use the relations functionality in QGIS.

See https://web.archive.org/web/20160313201132/http://blog.vitu.ch/10112013-1201/qgis-relations

This allows you show a table of related participants on the feature form of a zip code.

The QGIS 3.10 documentation of this feature is at https://docs.qgis.org/3.10/en/docs/user_manual/working_with_vector/attribute_table.html?#creating-one-or-many-to-many-relations

Dave X
  • 1,639
  • 13
  • 25
Matthias Kuhn
  • 27,780
  • 3
  • 88
  • 129
  • 2
    That a neat article thanks for sharing, can you expand this answer to include the parts that are relevant to this question? Sometimes links get broken and I think GIS.se tries to discourage link only answers. – SaultDon Jun 23 '16 at 16:53
  • 2
    The link to the blog post above is broken. Is there somewhere else that holds that post? – Johanna Mar 08 '17 at 04:23
0

You may use a processing scripts.

And here the one for an attributes cross-joining: https://github.com/kiselev-dv/QGIS-Processing/blob/master/scripts/spatial_cross_join_attributes.py

You may copy that script into {QGIS_HOME_DIR}/processing/scripts and use it via processing menu.

You have zip codes as an shape file, but I don't get in what form do you have survey data?

If they are points, import them as a new layer, and run spatial_cross_join_attributes script. It will asks you for two layers and name of results table. And in result table you'll get one row for each pair of zip and enclosed point.

zip1 point1
zip1 point2
zip2 point3
dmitry.v.kiselev
  • 1,666
  • 1
  • 11
  • 23