[Qgis-user] select by location using only selected feature in python console
Holly Wilkie
bells.holly at gmail.com
Fri Mar 17 13:54:45 PDT 2017
I have a shapefile of buffers "buffer300" of a network of proposed
transmission lines and a polygon file called "struct" of habitable
structures. I want to create a column associated with each of the buffers
in the "struct" file and populate it with a 1 or 0 to indicate whether or
not it intersects that buffer.
1.) I can select by attribute like this to select feature number 1001 from
"buffer300" :
buffer300.selectByExpression("\"PSI_Route\"='1001'")
2.) In order to select by location from "struct" using "buffer300" I tried:
import processing
processing.runalg('qgis:selectbylocation', struct,buffer300,'intersect',0,0)
Which is not working, so I haven't attempted my next step, which will be to
select by location using only the selected feature as the reference feature.
My intent is to do this for each buffer, so at the end my "hab_struct" has
an attribute for each of the 65 buffers with a 1 or 0 indicating whether or
not the feature intersects that particular buffer. I really need to
automate this.
I could do this logic in pure python no problem, but I'm not familiar with
using python in this context.
First things first, can anyone tell me what is wrong with my spatial query?
Secondly, is there a way to use only the selected feature in a spatial
query in the python console (or the graphical modeller for that matter.)
Any ideas?
Many thanks,
Holly Wilkie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20170317/6a846095/attachment.html>
More information about the Qgis-user
mailing list