1

I use QGIS 2.14. I have one layer for the points and one layer with many polygons. I'm having trouble finding the polygons that overlapped with the points. Is there a way to do this? I'm not asking for how many points are within the polygon, but the vice versa. How many polygons overlapped a certain point. Hopefully, I could have an attribute table with the points that has the overlapping corresponding polygon/s.

Here's a screenshot of what I'm working on.

enter image description here

7
  • I believe the answer in this post, while the reverse of what you're after, will be sufficient to solve your problem.
    – Fezter
    Commented Sep 7, 2017 at 4:13
  • @Fezter, Sir, thank you for your response. But what we're really looking for is for the polygon name to be added to the attribute table of the point. An example would be: If the point was to be named: HH1 and is overlapped by P1, P2, P3, P4... while HH2 is overlapped by P1, P2, P5... Is there a possible way this can be done, hopefully by batches since we are dealing with a big amount of data. Thank you Sir. and I appreciate any help and advice.
    – Kaye
    Commented Sep 7, 2017 at 5:25
  • I've reopened the question. I suggest you look into spatial joins.
    – Fezter
    Commented Sep 7, 2017 at 5:28
  • @Kaye Do you need the polygon's name to be added as a list in a field of the point layer? If yes, you will probably need some python to achieve this..
    – YoLecomte
    Commented Sep 7, 2017 at 9:02
  • @YoLecomte, Yes. That's what I want to achieve, hopefully without python since I only know basic QGIS as of now. Thank you for the advice. :)
    – Kaye
    Commented Sep 7, 2017 at 9:45

1 Answer 1

1

Easy to do with some python run in the QGIS console:

Copy and paste this code snippet in the editor of QGIS python console and change line as appropriate to fit your data

layer_to_update =  QgsMapLayerRegistry.instance().mapLayersByName('point_layer_name')[0] #change as appropriate (name of your point layer)
layer_to_join = QgsMapLayerRegistry.instance().mapLayersByName('poly_layer_name')[0] #change as appropriate (name of your polygon layer)

field_to_fill = layer_to_update.fieldNameIndex('point_layer_field') #change as appropriate (name of the field in the point layer thaht you want to fill

layer_to_update.startEditing()

for point in layer_to_update.getFeatures():
    gpoint = point.geometry()
    list = []
    for poly in layer_to_join.getFeatures():
        gpoly = poly.geometry()
        if gpoint.intersects(gpoly):
            list.append(poly['poly_layer_field']) #change as appropriate (name of the field where are stored the name of your polygons
    layer_to_update.changeAttributeValue(point.id(), field_to_fill,  ', '.join(list))

This will fill the point layer field you choose with a comma separated list of the overlapping polygons name for each point as shown in the 'poly' field below:

enter image description here

0

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.