3

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

  • 2
    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
2

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.

1

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.

1

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:

MMQGIS Spatial Join

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

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.