I have a road network shapefile, as well as a postgis layer of different areas in a city. The areas file contains one big polygon containing everything (the service area), and then a series of smaller polygons that split up the city by neighborhood. I want to assign info from the smaller neighborhood polygons to the road network based on location. If I do a simple spatial join, then the road network will get info from the larger service area, which I do not want. Is there an easy way to tell QGIS to exclude the service area from the join?

I realize I could export only the neighborhood polygons to a new file, then do a spatial join, but I would like to avoid creating a new file every time I have to do this (which will be weekly).

I am using QGIS 2.8.6 and Python 2.7. A script would be ideal, but I can use the graphical interface if necessary

Edit: I tried using the intersect tool, but it is going really slowly for my network layer of about 180,000 features (on track to take like 20 minutes). In the future I will need to do this for layers with over a million features, so this won't be acceptable

• Can you bring your shapefile into PostGIS? This could easily be done with a SQL query (... JOIN ... WHERE ...). – Richard Law Mar 9 '16 at 20:21

I recommend conducting the join on a SELECTION of the larger dataset, that way you don't actually have to make a new layer but you can limit the join to the selected features only.

I may not be understanding your question properly, and I do not have any data to use as an example, but if your service area polygon has a unique identifier, it would seem to me you could run a query where everything was selected but the service area, and the roads could have the updated neighborhood info input. This would only work without rewriting if the service area id remained consistent though.

The other question I would have is, are you splitting, or have the roads been split where they enter a new neighborhood? I could see a lot of conflicting issues with updates if this is not the case. I suppose a way around this would be to create a list of neighborhoods that each road travels through.

You could try using the Spatial Join tool from the MMQGIS plugin which may need to be downloaded/enabled from Plugins > Manage and Install Plugins. It should appear in the toolbar in which case you can go to:

MMQGIS > Combine > Spatial Join

Here you can select your layers, how they should be anaylysed (e.g. intersect, contains etc) and select the fields you want to keep in the output:

Just remember to change the path and name of the Output otherwise you may receive errors.