1

New user to GIS and to QGis but experienced data user.

I have shapefiles for a state legislative districts. I have a set of individual voter records that I have geocoded.

What I'd like to do is create a map where the color wheel displays the number of voters per legislative district. I'm not quite sure how I'll do the join (or even if I should use a join).

I know this is probably basic and I'm asking the question wrong but guidance appreciated.

1
  • do you want to color your polygons in dependence from your data , e.g. less than 5 voters = yellow, 5 to 10 voters = orange, nore than 10 voter = red. (this is a choropleth-map ) or do you want to display the voters as individual points (in different colors) within each polygon?
    – Kurt
    Commented Aug 13, 2013 at 6:24

2 Answers 2

2

I'd like to suggest an answer both to your question and to: this question which seems a very similar problem, using SpatiaLite. Actually this issue of summing a value from a point layer into the data table of a polygon layer appeared also here

If I have two shapefiles, one a point shape called "locations", and the other a polygon layer called "districts", then I import both into a SpatiaLite database, and run the following query:

First add a column to the "districts" table for the point totals, i.e.

ALTER TABLE districts ADD COLUMN ttl_voters integer;

Then use this update to get the totals into the polygon attribute column:

UPDATE districts SET ttl_voters = ( SELECT SUM(num_voters) FROM locations WHERE ST_Contains(districts.geometry, locations.geometry) );

Now load the two spatialite layers into QGIS, and setup a color table for the districts based on the ttl_voters column. In the Layer Properties -> Style tab choose "rule-based" rendering, etc ...

HTH, Micha

3
  • I just tried to use the plugin but till now it does not work like I want to. I made it to add a new column but it seems as if it does not work wirth the next command: Commented Aug 13, 2013 at 14:19
  • I can just edit the edit for 5 min so here the right comment: I just tried to use the plugin but till now it does not work like I want to. I made it to add a new column but it seems as if it does not work wirth the next command--> UPDATE districts SET ttl_voters = ( SELECT SUM(num_voters) FROM locations WHERE ST_Contains(districts.geometry, locations.geometry) ); <--- although I replaced all names with my filenames of course. I am not sure about 2 parts: SELECT SUM + ST_CONTAINS ... can you explain me something about these parts of the line please? Commented Aug 13, 2013 at 14:53
  • 1
    The SUM() SQL function will return a sum of the values in whatever column you enter. The ST_Contains causes the SUM to work only on the locations contained in a district. So you're getting a total of "num_voters" for all locations in each district separately.
    – Micha
    Commented Aug 15, 2013 at 14:52
0

If you just need to count the number of points in polygons, use the Points in polygon tool as described in http://qgis.spatialthoughts.com/2012/02/tutorial-spatial-analysis-points-in.html

enter image description here

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