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

Vince
  • 20,017
  • 15
  • 45
  • 64
Kaye
  • 13
  • 4
  • I believe the answer in this post, while the reverse of what you're after, will be sufficient to solve your problem. – Fezter Sep 07 '17 at 04: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 Sep 07 '17 at 05:25
  • I've reopened the question. I suggest you look into spatial joins. – Fezter Sep 07 '17 at 05: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 Sep 07 '17 at 09: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 Sep 07 '17 at 09:45
  • I will provide an answer with python because, I don't know how to do without. Hope someone will be able to find something. – YoLecomte Sep 07 '17 at 09:48
  • Is there a lot of polygon types (P1,P2,P3, etc) ? You could maybe union points and polygons. I think union will generate a duplicate point for each polygon it meets. you can then export everything into excel and generate a pivot table ? I haven't checked yet, just a hint; – gisnside Sep 07 '17 at 10:07

1 Answers1

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

YoLecomte
  • 2,895
  • 10
  • 23