Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is it possible in QGIS to query a layer with data from another layer?
And if so ... how is the syntax for that?

Usecase: I have a lot of image-position points and a lot of monitoring sites. I would like to set the monitoring area layer, so that it only shows areas where we also have images for this year.
I then use the extent of the monitoring area as the coverage layer to render my image-position maps with the Atlas plugin.
Without querying the areas to reduce them, i get a lot unneccesary maps with no image-positions, so i want to get rid of those areas which do not match (and of course not manually)

So, is there kind of a query to find out if a value in table1 column xy exists also in table2 column xy ?

share|improve this question
Could you add a sample map or visualization? It's rather hard to just imagine. – R.K. Oct 1 '12 at 7:34

A method I use to do something similar is as follows.

I go to the Vector Menu and use the Geoprocessing Tools to buffer my points layer. Then I go to the Vector Menu again and use the Data Management Tools and 'Join Attributes by Location' which adds the photos taken within the buffered area to a new shapefile.

share|improve this answer
Thanx for your hint, but the spatial way is no option in my case: The monitoring areas sometimes directly touch, and often images are taken from outside, but inside another area, into the respective monitoring area. To tidy up all those errors would maybe take as long as to manually select the proper areas. I think that my question is not answerable in my sense at the moment, cause there seems to be no such feature that i asked for. Best indicator for that is, that even underdark has no clue ;) Will maybe file a feature request ... – Bernd V. Aug 2 '12 at 8:37

Although it's a long time since the question was asked, I'm struggling to find a satisfactory answer. It seems that the questioner (and me!) are trying to perform directly on a shapefile the equivalent to the SQL statement:

SELECT * FROM <Layer1> WHERE <Layer1>.<field_x> = <Layer2>.<field_y>

I have found a way to do this in the "Select by Expression" query window of the shapefiles attribute table viewer:

getFeature('<layer2>', '<field_y>', attribute($currentfeature, '<field_x>')) IS NOT NULL

i.e. only select a record if an attempt to get the associated feature from the other table doesn't fail (i.e. return NULL).

This works but is quite slow and seems rather convoluted. Surely there must be a better way?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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