[GIS] Split Vector Points/Polygons by Vector Grid and assign to relevant grid

kmlqgisvectorvector-grid

I have 3 vector shapefiles (1: Point, 2: polygon, 3: vector grid) that I would like to combine so that the points and polygons are 'assigned' to the relevant grid cell within which they are contained, within a vector grid. I've attached a picture of what the vectors look like Example. Some of the polygons are across boundaries – I'd like them to be assigned to a single polygon (perhaps by which grid they are mostly located) as previously I have tried merge and they have been split. I am exporting this to KML to use in G/Earth Pro – previously I had the grid and then the points/polygons within a subfolder.

Is the last bit possible? It is likely a separate question.

Best Answer

You may use plugin spatialJoin, available from the official plugin repo.

I named the point layer "Islands" and the polygons "Coast".

situation

The points are WITHIN the grid cells.

spatialJoin WITHIN

The result are points having the attributes of the grid cell they are within (prefixed with "spj_").

Now the polygons. I suggest to convert them to centroids (Processing -> QGIS geoalgorithms -> Vector geometry tools -> Convert geometry type).

centroids

This results in a new layer with points position in the geometric center of the polygons. spatialJoin these centroids with the grid, as explained above, to get some output.

Now define an attribute join between the polygons (my "Coast") and the out from the last step.

attribute join

As you see on the last pic the Coast polygon now have an (joined) attribute Centroids_spj_fid, which contains the fid of the grid cell.

appended attributes

Related Question