[GIS] How to control line width in legend in QGIS

qgis

I have a map in which I am defining the sizes of various features in map units. When I come to generate a pdf of the map, using the Print Composer, the map itself is fine, but when I include a legend then the symbol elements of the lines are represented at a totally inappropriate size (e.g. a 'Main road' symbol swamps the whole legend).

I think it is the use of map units that is the cause of the problem as switching the line width to absolute units (e.g. mm) on the original map produces an appropriately sized line symbol in the legend. It seems like the legend that appears in the Print Composer is directly reflecting the way it appears in the Layer TOC – where, again, using map units produces oversized symbols relative to the map. However this is only true for lines. Point symbols rendered in map units appear exactly as I would expect in the Print Composer legend.

I would be very grateful if anyone can enlighten me as to whether this is a known problem, my misunderstanding of something, or there is a solution/setting/trick that I have missed.

I'm using QGIS 1.7.4 on Mac OSX 10.6.

Thanks for any help.

Phil

Best Answer

Phil, I too have struggled with this, but have a workable solution to use map units and a display a reasonable legend, until independent setting of legend line thickness is supported. You are using 1.7.4, so you can utilize this workaround, as it leverages the new symbology options.

Let's assume your map is in UTM (map units of meter) and you want your 'Roads' layer classified by type with a different symbol thickness in map units for relative display purposes (i.e. not real-world accuracy):

Road > Width
Highway > 20 m
Secondary > 10 m
Gravel > 5 m

For your Roads layer, you will need to make a new column in your data source of type real, with an appropriate size and precision for your use, lets call it 'ledgscale'. Edit your data and input the road width (in meters, as above) in the ledgscale column. There are many tools in QGIS for auto-updating your data relative to the road type column (Field Calculator, SQL, etc.).

The ledgscale column will scale your road type symbol's base width in map units.

Open the layer properties dialog for the Roads layer and go to Style, then choose to use New Symbology. Choose Categorized for symbol method, and set the Column to whatever your road type column is. Before clicking the Classify button, change the default symbol. Set the symbol's Unit to Map Units and the width to 1 (i.e. 1 meter, in this case). This will be used as a basis for the size in the legend later, and for scaling to your desired map units width for map features.

Click Classify to generate your road type symbols. Click the Advanced button and choose ledgscale under the Size scale field sub menu. This will scale your base symbol width by the ledgscale integer for each feature:

Highway -> (symbol width of n map units) * (ledgscale of 20) = output of legend at (n * 0.3 mm) and map feature at n * 20 map units width
or
Highway -> (1 meter) * 20 = legend of 0.3 mm and map feature of 20 meters

The 0.3 mm seems to be the default size for legend line widths (and other composer lines, like frames). This seems to be similar to the default of 0.26 mm for symbol lines.

You can do this technique with the other symbol methods, i.e. Single, Graduated, and Rule-Based. Rule-Based is the most flexible, albeit complicated.

Caveats: Changing the symbol's width beyond/below 1 (say to increase/decrease the size of the line in the legend) will affect that symbol's width on the map as well. You will also have to adjust the ledgscale number for all features that use that symbol.

This wacky workaround is how I have found to make it work, but coding QGIS to support fully independent control over legend line size is the correct solution.

References:
http://lists.osgeo.org/pipermail/qgis-developer/2010-February/009019.html
http://hub.qgis.org/issues/2979

Related Question