I would like to be able to click on a point on a map to select all vector features (from multiple layers) within a specified radius of the point. Can anyone point me in the direction of how to do this please?

The Spatial Query plugin selects only features from 1 layer at a time, and the search radius is only attainable by creating a point, then creating a buffer polygon and using the buffer polygon as a reference feature. Therefore I would have to run this plugin for each layer I'd like to select from. I'm hoping there might be a more simple/less time consuming method.

Ideally I would like to be able to run this spatial query from shapefiles displayed in the QGIS 2.0 GUI, but if it's not possible, the shapefiles are eventually being exported to a PostgreSQL database, so some advice on how to run this type of spatial query from a PostgreSQL database would be really useful also, as I have very limited experience in using them.



I think if you set up a PostGIS view that created a buffer on points in the layer you're editing in QGIS, and then queried the vector features the layer you're trying to query, you could do this.

A great example is the blog post and video by Tim @ Linfiniti found here


So answer to question, no there is no way that i know do to do this in QGIS without creating custom python plugin (but i know postgresql better than qgis)

for postgresql, here some tips

CREATE OR REPLACE VIEW lines_touching_buffer AS
SELECT * from lines l WHERE l.geom && ST_GeomFromEKWT(insert your ewkt here) ;

That creates view which displays all rows from lines table witch bounding box overlaps with given geom

Now assuming that you want view all tables

SELECT table_schema,table_name
FROM information_schema.tables
ORDER BY table_schema,table_name;

You could do something like for loop over all tables in schema and create view with given polygon and where clause. Something like this into function for loop

FOR i IN SELECT table_schema,table_name
    FROM information_schema.tables WHERE table_schema LIKE 'public' 
    ORDER BY table_schema,table_name;

                SELECT l.* 
                FROM %2$I l ', 'view' , i.table_name, 'something');


note: see how format() works. you need to implement above code into plpgsql funtion

You could even create table that has buffer geoms and use above for loop to loop over all tables and create view for every buffer in buffers table ( it would be wise to use if(i.table_name == buffer table) , also adding dynamic view creation to that buffer table update/insert trigger would do that automatically. Only thing left for user would be adding those new views to QGIS project.

  • thanks very much for your response, I will try the code out. – ffinnm Mar 21 '14 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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