Diagrammen met objecten per locatie

Imagine you have a list of different features at locations and you want to display those on a map like this:
The QGIS diagrams expect a column for each pie or bar, but our features are all listed in one column:
And our geometry is stored in a good old shapefile:

Shapfile 'cities.shp'
Shapfile ‘cities.shp’

So, we can use the ‘code’ field for joining as well as for grouping the items to one single row per location.
Since QGIS vector joins cannot handle 1:n relations, we are going to use a virtual layer for this. In a virtual layer you can use all sql that sqlite supports, including JOIN and GROUP BY statements.
So we create a new virtual layer ‘cities_grouped’ with this sql:
[code language=”sql”]
group_concat(amenity) AS amenities,
CASE WHEN INSTR(group_concat(amenity),’university’) > 0 THEN 1 ELSE 0 END AS university,
CASE WHEN INSTR(group_concat(amenity),’airport’) > 0 THEN 1 ELSE 0 END AS airport,
CASE WHEN INSTR(group_concat(amenity),’station’) > 0 THEN 1 ELSE 0 END AS station,
CASE WHEN INSTR(group_concat(amenity),’harbor’) > 0 THEN 1 ELSE 0 END AS harbor,
count(*) AS cnt,
FROM amenities a
LEFT JOIN cities c ON a.code = c.code
GROUP BY c.code, c.geometry
The attribute table of this new virtual layer looks like this:
Virtual attribute table 'cities_grouped'
Virtual attribute table ‘cities_grouped’

We can use diagrams as symbology for this new layer, adding in all the new columns university, airport, station and harbor. I used the count column (cnt) for sizing the diagram and offsetting the labels.
Hope this helps you, and if you know an easier way for doing this please let me know!

Gray is the new Black

Sometimes I prefer to publish my map in gray instead of black. But all newly added QGIS composer items are set to black by default.

Turn Gray dialog
Turn Gray dialog

For changing the colors more easily and rapidly I created the “Turn Gray” plugin. By default it changes all foreground colors (labels and outlines) to gray. But you are free to choose more cheerful colors too. And for the background as well.
Right now not all composer items are supported, but the map, legend, labels and scale bar do. Tables, arrows and map grids will have to wait.
I hope others will be happy to use this tool as well, that’s the idea behind open source!
Here some examples:
original map composer
original map composer

turned to gray (default plugin values)
turned to gray (default plugin values)

turned to red foreground and lime green background
turned to red foreground and lime green background

Kleurinstellingen voor WMS- en WMTS-kaartlagen

An advantage of using map services like WMS and WMTS is that your styling has been done by someone else. But this can turn into a disadvantage as well in case the colours of your overlay are similar to the colours in your remote base layer.
To show this I created an example using the Dutch Top10NL topographic map (WMTS) with my own random polygon layer in random colours on top of it. Because of the bright and colourful Top10NL my own features are hard to distinguish.
In QGIS master (soon QGIS 2.0) I discovered a new feature. For WMS and WMTS layers it is possible to adjust the colours. You can change brightness, saturation and contrast. It is also possible to display the layer in grayscale or adjust the colour (hue), for example to purples. (It’s still a matter of taste…)
Some examples:
adjusted brightness and contrast
purples Read More