Visualize flows with FlowMapper

This article explains the presentation of flows on a map, using the FlowMapper plugin. For this demonstration, data on commuting patterns between 40 regions are used (from Statistics Netherlands).

Example of FlowMapper output (post-processed)
Example of FlowMapper output (post-processed)

Preparing the data

After the plugin is installed in the usual way, the manual can be found in the folder C:\Users\{username}\.qgis2\python\plugins\FlowMapper2_documentation.Three text files are required, with node coördinates, node names and a flow matrix. Three points must be stressed that are not mentioned in the manual. 1) The plugin does not work well with numbers with decimals. That can be solved by multiplying the numbers by (e.g.) 1000 and then round them. 2) As delimiters, both spaces and tabs may be used. The latter is especially useful when pasting data into a text file from Excel. 3) The node names should not contain spaces, because these are handled as delimiters. Replace them with underscores.

Continue reading Visualize flows with FlowMapper

Generate series of maps with Python script

Sometimes you need to produce a series of similar thematic maps. The only difference is the field used to colour areas or show graduated symbols. Classifications or maximal symbol sizes are identical. For large numbers of maps it is quite annoying to repeat the same actions in QGIS over and over again. Moreover, mistakes are easily made this way. This article explains how the production of large numbers of maps can be automated with a Python script. All files needed to try this method are available in a ZIP file. This is a modified version of a previous article. This new method works better and faster than the previous one en works the same for Windows and Linux.

Continue reading Generate series of maps with Python script

Generate a series of maps 2 (Linux)

In a previous article I described how you can let QGIS generate a series of thematic maps with a batch file. This method was meant for the Windows version of QGIS. Now I have written a similar shell script for Linux (‘projectsnapshots’). You can find it in the ZIP file included with this article. It also contains all other files you need to test the script and an example of the result. The result consist of a series of images and a HTML showing all maps. The content could be copied and pasted in a word processing file. Before the script can be run, you have to make it executable. For further instructions I refer to the previous article. The script was tested with openSUSE 12.3. It works with QGIS 1.9.0-Master, but unfortunately not with QGIS 1.8.

Shell script to generate series of maps

Download ZIP file with shell script and sample files

Graduated symbols

Graduated symbols are the best way to visualize absolute numbers like population size. Usually the area of the symbols is made proportional with the number to be displayed. This is especially important if the values are far apart.

Methods

QGIS 1.8 offers four methods to display graduated symbols. All can be found in the dialogue ‘Layer properties’, on various tabs. The next table summarizes advantages and disadvantages of these four methods. ‘Old symbology’ is not discussed here. Continue reading Graduated symbols

Move centroids (2)

If you want to influence the locations where labels, symbols or diagrams are displayed within areas, it is useful to have a separate layer with centroids. This article demonstrates how such a map layer can be created and modified in QGIS. The Dutch provinces are used as an example. This is a revised version of an  earlier article (in Dutch), adapted to new possibilities in QGIS.

Continue reading Move centroids (2)

Generate a series of maps

[For a modified version, go to this article.]

Sometimes you need to produce a series of similar thematic maps. The only difference is the field used to colour areas or show graduated symbols. Classifications or maximal symbol sizes are identical. For large numbers of maps it is quite annoying to repeat the same actions in QGIS over and over again. Moreover, mistakes are easily made this way. This article explains how the production of large numbers of maps can be automated. The steps are described for Windows, but it wouldn’t be difficult to develop a similar procedure for Linux.

Continue reading Generate a series of maps

Directly use data from Excel file

In response to my previous article about joining data from a csv file, I received a very good tip. From QGIS 1.8 Excel files can be opened directly in QGIS. Strange enough, nothing is mentioned about this in the ‘release notes’. It only works with the older XLS-format, not with the newer XLSX format.

You can open an Excel file with the menu option or button ‘Add new vector layer’. That is confusing for non-spatial data. Your Excel file should contain a column to be used to join both layers. Further, you need one or more columns with the data you want to display. Co-ordinates are not required. Set the file type filter to ‘All files’. Otherwise your Excel-file will not be visible. The dialog doesn’t contain a special filter for Excel files.

If all went well, you can now join the table to a spatial layer, like described in my previous article.

Join data from a CSV file

In a previous article I have shown how data from a text file with points can be displayed as an additional layer on top of a layer consisting of areas. There was no connection between de data from both layers. This article explains how areas in one layer can be coloured based on data from a text file in another layer. As an example the proximity of department stores in Dutch municipalities in 2010 is used.

Continue reading Join data from a CSV file

Bar charts with legend

This article describes how to create a map with bar charts and a legend.

Required software
Quantum GIS (qgis.org)
LegendSVG (qgis.nl)
Inkscape (optional) (inkscape.org)

Required files
Map layer with areas
Map layer with data

As an example, a vector map of the Dutch provinces is used. On top of this a layer is placed from a csv file. It contains the x and y coordinates of the centroids and the number of inhabitants by province, divided into three age groups.

Limitations
This technique is not suitable if a lot of areas are to be displayed. The map would become very cluttered. Another limitation is that bar width is not adjustable.

Preparation
Make sure the required layers have been opened and are fully visible.

Displaying bar charts

Select the properties of the layer with the data (right mouse button) and go to the tab ‘Overlay’. Put a check mark before ‘Display diagrams’ and select ‘Bar chart’ as chart type. Now, the attributes can be added one at a time. In this case, the population numbers per age group. Select an attribute, click ‘Add’, and repeat this for the other attributes.

Now you must specify the bar height. Usually, the attribute with the highest maximum value at the regional level will be used to determine the maximum bar height. Unfortunately, that will go wrong if this attribute is zero in one or more regions. Click ‘Find maximum value’ to determine the maximum value for the selected attribute and set the maximum bar height (‘Size’). In the current stable version of QGIS (1.7.4) it has no effect to select ‘Map units’ as size unit in stead of millimeters. Click ‘Apply’ to see the effect of the settings on the map. If necessary, move the dialog somewhat to the left, in order to see the map. Write down the settings for maximum value and maximum bar height. You will need this information later, if you create a legend. If the result is what you want, click ‘OK’ to exit the dialog box.

You can also enter the maximum value manually. For the readability of the legend it is better to use a rounded number.

Sometimes you also need to make the points symbols 100 percent transparent (on the ‘Style’ tab). Otherwise, point symbols will appear in areas with very low values ​​for the selected attributes.

Create legend

Currently, QGIS has no option to automatically create a legend for a map with bar, pie or circle charts. For this I wrote the program LegendSVG, to be downloaded on this site. Unzip the file somewhere on your computer and double click LegendSVG.exe.

With this program, a map legend in SVG format can be made. The legend can be added to the map in the Print Composer. LegendSVG uses points a measuring unit. One point is 1/72 inch and one inch is 2.54 cm. Dimensions in millimeters (S) can be converted to points with the formula: 72 x S / 25.4.

First, select the chart type (‘Bar chart’). The bar height and the corresponding maximum value that you wrote down, can be filled in at ‘Object size’ and ‘Maximal value’. At ‘Categories’, set the number of bars to 3. Because the bars have a fixed width of 5 mm in QGIS, you don’t have to change ‘Bar width’. Now you can customize all text that will appear in the legend. For the different ways to set the colors I refer to the help text of the program. Legend height is calculated automatically, based on the data you have entered. This is not (yet) done with legend width. If the settings are complete, click on the ‘Build SVG code’ button. Several lines of code will appear. A SVG file is basically a text file. Now save the results with the ‘Save to file’ button. Choose a filename. The file extension should remain ‘svg’. With the ‘Show measures’ button you can see what the dimensions in millimeters have become. Write these dimensions down, because you will need them later in QGIS.

Before you combine the legend with the map in QGIS, you can inspect the result with Inkscape. With this program you can modify the legend, if you wish. You could also choose to finish the entire map with Inkscape, or some other graphical program. However, this will not explained further.

Map lay-out

Open a new Print Composer (“Print layouter”) from the ‘File’ menu. Make sure the map is displayed and add a title. The legend can now be added with the ‘Add image’ button. You can also use the ‘Layout’ menu. Now click on the spot where the legend should appear. A white rectangle appears. Select this rectangle and in the right panel on the ‘Item’ tab enter the right size (unfortunately, QGIS unfortunately does not do this automatically). Then open the legend file using the button with the three dots next to the ‘Load’ box. If all went well the legend will appear.

Now it may seem as if something went wrong. In the current stable version of QGIS (1.7.4) the appearance of the bars in the Print Composer differs from the appearance on the map canvas. After you save the map with ‘Export as image’ or ‘Export as SVG’, the size of the bar charts on the map will match the size on the legend again.

You can also save your map in PDF format, but currently the menu option ‘Export as PDF’ does not work well with bar charts. You can solve this by printing to a virtual printer such as PDF Creator. Continue reading Bar charts with legend