Monday, 7 August 2017

qgis - Select polygons with other polygons layer?



I have to select some polygons with another polygon layer. I have to select green polygons using relevant overlapping percentage with the purple ones. In this particular example, I would like to select all green polygons except the third one from starting from above for example.



Do you have any advice to do that?


enter image description here



Answer



I am not sure how best we can define "adequate". But assuming over 50% of the green polygon is overlapping with purple:



  1. Go to Layer | Add Layer | Add/Edit Virtual Layer

  2. [Import] (greens and purples) layers


An example of query is:


SELECT greens.*   FROM greens, purples

WHERE st_area(st_intersection(greens.geometry, purples.geometry))
> 0.5 * st_area(greens.geometry)

If you need a higher threshold e.g. 'at least 60% of green polygon has to overlap with purple' then change 0.5 to 0.6.




If you want to decide it by the greens' centroids' location.


SELECT greens.*   FROM greens, purples
WHERE st_within(st_centroid(greens.geometry), purples.geometry) = 1

No comments:

Post a Comment