[GIS] One-to-Many Spatial Join in QGIS

attribute-joinsqgisrelatesspatial-join

I am trying to join attributes from 2 shapefiles. 1 shapefile is a polygon layer indicating police precincts and the second is a point layer with crime statistics for each police station. The police station and the police precinct are the same.
The police station layer that contains the crime statistics has roughly 40 points per police station. See attached police station image

enter image description here.

I want to join this layers table to the police precinct layer (See attached precinct layer image)

enter image description here

The trouble I am having with this, is that when i use the Join by location tool, it only takes the first 17 records from the police stations layer and appends the data to the existing 17 police precincts.
I need it to append all 40 crimes points to the precincts layer without creating 40 polygons that lie ontop of oneanother. Just 1 polygon with multiple crime records.
Does anyone know how to do this in QGIS?

Best Answer

If I understand this correctly, you don't need a spatial join. Use Project > Project Properties > Relations. Use 'Precincts' as the parent and 'Stations' as the child. Use "Station" and "COMPNT_NM" as the join fields.

Edit: If you then use the identify features tool and click on a precinct, you will get a form pop up with all the attributes for the precinct plus a list of all the associated crimes. See the documentation for further details

Related Question