[Qgis-user] Scale based label rendering

Andreas Neumann a.neumann at carto.net
Wed Nov 6 08:54:22 PST 2013


Hi Ross,

I sucessfully use $scale - it should just work, otherwise it is a bug 
either in your statement or in QGIS.

I guess in your example your statement is wrong as AND/OR can only be 
combined with boolean values (true/false). In your case you combine a 
number with another number with OR and of course your statement fails.

You could write your statement with nested CASE statements, such as:

CASE WHEN type = 'town' THEN
     CASE WHEN $scale < 100000 THEN 15 ELSE 10 END
   WHEN type = 'city' THEN
     CASE WHEN $scale < 100000 THEN 20 ELSE 15 END
END

You should get a warning if the syntax in your statement is not correct.

Andreas


Am 2013-11-06 17:44, schrieb McDonaldR:
> Thanks Bernhard
> 
> That does work.
> 
> Any idea how the $scale function works then?  It is supposed to return
> the current scale of the map canvas but is only available in some
> contexts and will be 0 otherwise.
> 
> Ross
> 
> -----Original Message-----
> From: qgis-user-bounces at lists.osgeo.org
> [mailto:qgis-user-bounces at lists.osgeo.org] On Behalf Of Bernhard
> Ströbl
> Sent: 06 November 2013 16:02
> To: qgis-user at lists.osgeo.org
> Subject: Re: [Qgis-user] Scale based label rendering
> 
> Hi,
> 
> not a solution but a workaround:
> simply copy the layer and define a different visibility scale range.
> 
> Bernhard
> 
> Am 06.11.2013 16:54, schrieb McDonaldR:
>> Hello list
>> 
>> I want to vary the size of my labels on features both by attribute and 
>> map scale.  So, for example, I have a layer of towns and villages and 
>> I want towns labelled with a font size of 20 and villages with a font 
>> size of 10.  I can do this with in the label size expression builder:
>> 
>> CASE WHEN "type" = 'town' THEN 20 ELSE 10 END
>> 
>> Now, how can I vary the label size with scale?  When the scale is 
>> smaller than 1:100000 then towns must be size 15 and villages size 8.  
>> I thought something like this would work:
>> 
>> (CASE WHEN "type" = 'town' AND $scale<  100000 THEN 20 ELSE 10 END) OR 
>> (CASE WHEN "type" = 'town' AND $scale>  100000 THEN 15 ELSE 8 END)
>> 
>> I tried with the $scale function under Record category but then the 
>> labels disappeared.
>> 
>> Any suggestions?
>> 
>> I am using QGIS 2.0.1-3 on Windows 7.
>> 
>> Thanks
>> 
>> Ross
>> 
>> Ross McDonald | GIS Data Coordinator | Resources Department, IT 
>> Division | Angus Council, Angus House, Orchardbank Business Park, 
>> Forfar, DD8 1AT
>> T: 01307 476419 | F: 01307 476401 | E: 
>> mcdonaldr at angus.gov.uk<mailto:mcdonaldr at angus.gov.uk>  | W: Angus 
>> Maps<http://www.angus.gov.uk/maps/map_home.cfm>
>> 
>> This message is strictly confidential. If you have received this in 
>> error, please inform the sender and remove it from your system. If 
>> received in error you may not copy, print, forward or use it or any 
>> attachment in any way. This message is not capable of creating a legal 
>> contract or a binding representation and does not represent the views 
>> of Angus Council. Emails may be monitored for security and network 
>> management reasons.  Messages containing inappropriate content may be 
>> intercepted. Angus Council does not accept any liability for any harm 
>> that may be caused to the recipient system or data on it by this 
>> message or any attachment.
>> 
>> 
>> 
>> __________ Information from ESET Mail Security, version of virus 
>> signature database 9013 (20131106) __________
>> 
>> The message was checked by ESET Mail Security.
>> http://www.eset.com
>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-user
>> 
>> 
>> __________ Information from ESET Mail Security, version of virus 
>> signature database 9013 (20131106) __________
>> 
>> The message was checked by ESET Mail Security.
>> http://www.eset.com
>> 
> 
> -
> 
> 
> __________ Information from ESET Mail Security, version of virus
> signature database 9013 (20131106) __________
> 
> The message was checked by ESET Mail Security.
> http://www.eset.com
> 
> 
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
> 
> This message is strictly confidential. If you have received this in
> error, please inform the sender and remove it from your system. If
> received in error you may not copy, print, forward or use it or any
> attachment in any way. This message is not capable of creating a legal
> contract or a binding representation and does not represent the views
> of Angus Council. Emails may be monitored for security and network
> management reasons.  Messages containing inappropriate content may be
> intercepted. Angus Council does not accept any liability for any harm
> that may be caused to the recipient system or data on it by this
> message or any attachment.
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user



More information about the Qgis-user mailing list