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.

  • What about running the Intersect tool for the points and grids layer and again for the polygons and grids layer? The outputs should contain attributes from the original layer and from the grid layer (e.g. ID, XMIN, XMAX etc.).
    – Joseph
    Commented Jan 26, 2016 at 16:19
  • Thanks for the comment. The intersect works for the points - the problem is that the polygons are split by the vector boundaries
    – Darren J
    Commented Jan 26, 2016 at 16:31

2 Answers 2


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

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


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).


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


Another spatial-join method (similar to what @Detlev posted) is to use the Join attributes by location tool from either the toolbar (Vector > Data Management Tools > Join attributes by location) or from the Processing Toolbox.

You can use this for both your points and polygons where each should receive the attributes (including the ID field) of the grid.

Note that if a polygon crosses more than one grid square, the upper left-most square will be joined to the polygon regardless of how much of the polygon lies within it. So you could obtain slightly different results from this method and @Detlev's smart method as his focuses on using the centroid of each polygon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.