On Aug 2, 2011, at 1:47 PM, Alastair Aitchison wrote:

> Hi list,
>  
> I'm trying to plot OS Mastermap data using Mapnik, and am having a bit of 
> trouble with the placement of the cartographic labels.
> Rather than having the labels sourced from shape attributes, the dataset 
> defines all label text as separate features with:
> - a point location
> - the anchor location of the text relative to the point (i.e. Top left, 
> Middle bottom etc.)
> - the angle at which the text should be oriented (rather curiously, measured 
> as an integer value in 10ths of a degree from 0 - 3599)
>  
> If I use a TextSymbolizer with placement=point, then I can place the labels 
> at the correct position relative to the point using a combination of the 
> vertical_alignment and dx/dy properties, but there doesn't seem to be any way 
> to specify the angle at which the text should be drawn. (i.e. there's no 
> equivalent to MapServer's ANGLE property)

Mapnik2/trunk does support angles, and reading them from a database field. So, 
this will be available in the next release.

Also Hermann Krauses recent work, also just in the trunk development code, has 
support for anchors: 
http://mapnik.org/news/2011/jul/13/new_text_placement_system/

>  
> So, instead, I've been applying some old-school trigonmetry to artificially 
> create lines at the appropriate angle, either starting or ending at the 
> anchor point in question, and drawing the text on the line using a 
> TextSymbolizer with the placement=line model instead. It's a lot slower, 
> since it's probably invoking lots of clever "wrapping text to wiggly lines" 
> computations that aren't required for my single line segment scenario, but it 
> does (nearly) get the results I want.
> The problem I now have is that, by using the placement=line model, I appear 
> to have sacrificed the ability to specify whereabouts along the line the 
> label gets placed - there is no horizontal-alignment attribute when using a 
> TextSymbolizer on a line as far as I can tell - the label is always placed in 
> the centre of the line.

Yes, unfortunately horizontal-alignment is not yet implemented for line 
placement.

> That means the only way I can get the label drawn in the right place is if I 
> create the line to be exactly of the right length for the label to fit. If I 
> create it too big, the label is effectively "padded" away from its anchor 
> point (which lies at one end of the line) and misplaced. But, if I create the 
> line too small, the TextSymbolizer label attached to it won't be rendered at 
> all. The problem is that, seeing as I'm using a non-fixed width font, the 
> length of the text string (and therefore the offset) is different for every 
> individual label - I've tried computing an approximate line length per length 
> of label, but it's not reliable enough to be used.
>  
> Does anybody have any smart workarounds (or perhaps, a magical text-angle 
> property that I'm unaware of!) as to how to create angled text anchored to a 
> point?

See above! :)

>  
> Thanks!
> _______________________________________________
> Mapnik-users mailing list
> [email protected]
> https://lists.berlios.de/mailman/listinfo/mapnik-users

_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to