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.
2 Answers
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... >
-
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 withWHERE Tree_Type.Feature_Ty IN ('Apple', 'Pear', 'Orange')
but this doesn't work either. Any thoughts?– DunutsDec 13, 2020 at 9:19 -
I can assume that your polygon file has the wrong geometry... Dec 13, 2020 at 9:47