Sunday 28 February 2016

qgis - Querying through Relations


Right now I am stumped on how to get two layers to interact. I have one layer that is just a map with town borders, with attributes for town codes. My other layer are data for businesses, wages for example. I setup a relate in the project properties menu between them using town codes, and I can see in the attribute table the the map layer knows what businesses exist in each town now.


However, I can't seem to make use of it. If, for example want to select by expression to just select towns where the average wage is over a certain level, I can't even begin because I can't write an expression using values from both layers, even though I set them up in a relation. How would I really go about doing this?


I am trying to figure out how to query, select, or anything using attributes from two related layers.



Answer



I'd suggest a two step process:




  1. If your businesses do not have the town codes associated with them, then you need to do a spatial join. In QGIS this is under Vector - Data Management Tools - Join Attributes by Location. The target layer will be your businesses and the join layer will be the towns (I'm assuming the towns are a polygon layer). Every business (assuming these are points) will be assigned the attributes of the town where it is located. Once this is done, you'll be able to query the new business layer using the attributes of the towns - and create summary tables (next step).





  2. If you want to join summarized data from the businesses back to the towns (so you can map by town or do town-based queries) you'll need to download a QGIS plugin that will allow you to sum by attributes to create new tables. Under Plugins - Manage and Install Plugins, take a look at Group Stats or Statist. You can use one of these to summarize the businesses by the town attributes you assigned in step 1, to create average wages for the town (for example). Once you have business data summarized by town, then you can do a regular one to one attribute table join, to join your summary table back to the towns layer to map the summarized data.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...