Defines a map that can be drawn
Parameters: |
|
---|
Applies styles to the features in the datasource
Parameters: |
|
---|
>>> feature = Feature(
... geometry=Geometry(type='LineString', coordinates=[[2, 2], [4, 8], [6, 2], [8, 8]]),
... properties={'road': 'major'}
... )
>>> style = Style(
... rules=[Rule(symbolizers=[LineSymbolizer(color=Color(0, 255, 255), width=24, join='round')]),
... Rule(symbolizers=[LineSymbolizer(color=Color(0, 0, 255), width=8, join='round')])]
... )
Applies a list of symbolizers to a datasource’s features.
Parameters: |
|
---|
If the filter is specified then the feature must pass the filter before the symbolizers are applied.
If the min or max scale is supplied then the geometries are drawn if the drawing context’s scale >= min_scale and < max_scale
A map scale is the proportion of device units to the map units they represent. For example if a device represents 1000km as 1cm then the scale is said to be 1/100000.
In Shelley the scale is defined by the denominator of the scale assuming a numerator of 1. So a scale of 1/1000 is represented as 1000.
Because a pixel in an image can be different sizes dependant on the monitor being used we assume a pixel size of 0.28mm square.
So for a scale of 1/1000 (denominator=1000) a pixel would represent 0.28mm X 1000 = 2800mm = 28cm = 0.28m
>>> style = Style(
... rules=[Rule(symbolizers=[LineSymbolizer(width=1)], max_scale_denom=10),
... Rule(symbolizers=[LineSymbolizer(width=5)], min_scale_denom=10)]
... )
TODO need to show map bounds to illustrate determination of scale
>>> style = Style(
... rules=[Rule(symbolizers=[LineSymbolizer(width=1)], filter=Filter("[road] = 'minor'")),
... Rule(symbolizers=[LineSymbolizer(width=5)], filter=Filter("[road] = 'major'"))]
... )
>>> feature = Feature(properties={'building': 'factory', 'stories': 5})
>>> Filter("[building] = 'school'").passes(feature)
False
>>> Filter("[building] = 'factory'").passes(feature)
True
>>> Filter("[building] <> 'mosque'").passes(feature)
True
>>> Filter("[building] = 'factory' or [building] = 'school'").passes(feature)
True
>>> Filter("[building] = 'factory' and ([stories] <= 2 or [stories] > 4)").passes(feature)
True
>>> Filter("not ([building] = 'shop') and [stories] < 6").passes(feature)
True
Mapnik has an xml map definition format.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map bgcolor="#b5d0d0" srs="+proj=latlong +datum=WGS84">
<Style name="style1">
<Rule>
<PolygonSymbolizer>
<CssParameter name="fill">#006620</CssParameter>
</PolygonSymbolizer>
<LineSymbolizer>
<CssParameter name="stroke">#00aa20</CssParameter>
<CssParameter name="stroke-width">0.2</CssParameter>
<CssParameter name="stroke-linejoin">round</CssParameter>
</LineSymbolizer>
</Rule>
</Style>
<Layer name="world">
<StyleName>style1</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">${buildout:directory}/parts/world-data/TM_WORLD_BORDERS-0.3</Parameter>
</Datasource>
</Layer>
</Map>
We can read this map definition with Shelley.