3

I have thousands of polygons (buffers) in a single layer and I have a points layer containing tree species. The tree species points shapefile has an attribute called Tree_Type. I need to select only the polygons that contain/intersect three particular species (as shown below). I've already tried multiple intersects to no avail. enter image description here

2 Answers 2

3

Using the new virtual layer with the SQL script in the form window add 2 layers and run the SQL script:

SELECT DISTINCT (a.geometry) geom FROM buffer a JOIN tree_pts b ON ST_Intersects(a.geometry, b.geometry) WHERE b.tree_type='pear' OR b.tree_type='apple' OR b.tree_type='orange'

Save the result as a new file using <Export>-<Save objects as... >

2
  • I'm trying this in PostGIS now as QGIS was crashing. I've tried using AND to get each buffer that contains all tree_types but it doesn't work? I've also tried the above code with WHERE Tree_Type.Feature_Ty IN ('Apple', 'Pear', 'Orange') but this doesn't work either. Any thoughts?
    – Dunuts
    Dec 13, 2020 at 9:19
  • I can assume that your polygon file has the wrong geometry... Dec 13, 2020 at 9:47
2

You can use first the processing tools "join attributes by location" and next "Dissolve" to remove duplicates. Yours polygons need to have a unique id attribute. enter image description here enter image description here enter image description here enter image description here enter image description here

Your Answer

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

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