Text Symbolizer

Renders text for features.

class shelley.symbolizers.TextSymbolizer(property_name, face_name, size, color='black', placement='point', halo_radius=None, halo_color='white')
Parameters:
  • property_name – name of the features property whose value will be used as text
  • face_name – font name
  • size – size of font
  • color (string or Color object) – color of line, defaults to black
  • placement – ‘point’ or ‘line’, defaults to ‘point’
  • halo_radius – increment in size of font used for halo, no halo is shown if None
  • halo_color (string or Color object) – color of line, defaults to white

Placement

Point geometries

For features with point geometries the text symbolizer places the text centered both vertically and horizontally at the point

>>> symbolizer = TextSymbolizer(property_name='title', face_name='Sans', size=10, color=Color.name('red'))
>>> point_feature = Feature(geometry=Geometry(type='Point', coordinates=[5, 5]),
...                         properties={'title': 'Primary Peak'})

Need to add a point symbolizer as well to see placement

.scratch/text_point.png

Line geometries

For line geometries the text can be placed at the center of the line, placement “point”, or along the line, placement “line”.

The default placement is “point”.

>>> line_feature = Feature(geometry=Geometry(type='LineString', coordinates=[[1, 1], [9, 9]]),
...                        properties={'title': 'Simple Street'})
.scratch/text_line_placement_point.png
>>> symbolizer.placement = 'line'
.scratch/text_line_placement_line.png

For lines with segments the text follows the angle of the line

.scratch/text_segmented_line.png

Polygon geometries

>>> polygon_feature = Feature(
...     geometry=Geometry(type='Polygon',
...                       coordinates=[[[1, 1], [5, 8], [9, 9], [5, 2]]]),
...     properties={'title': 'Lake Diamond'}
... )

With placement ‘point’ the text is placed at the centroid of the polygon.

>>> symbolizer.placement = 'point'
.scratch/text_polygon_placement_point.png

TODO: rendering a polygon with placement ‘line’

>>> symbolizer.placement = 'line'
.scratch/text_polygon_placement_line.png

Halo

If a halo attribute is specified the text is drawn twice. Once with the line width of the text increased by the halo radius and in the halo colour and again with normal line width and colour.

>>> symbolizer = TextSymbolizer(property_name='title', face_name='Sans', size=10, color=Color.name('red'), halo_radius=1, halo_color=Color.name('black'))
0 .scratch/text_halo1.png
2.5 .scratch/text_halo2.png
5 .scratch/text_halo3.png

An halo example with line placement

.scratch/text_halo.png

Table Of Contents

Previous topic

Polygon Symbolizer

Next topic

Data sources

This Page