User:Moresby/Understanding Mapnik/Revisiting our examples in XML

From OpenStreetMap Wiki
Jump to navigation Jump to search
Understanding Mapnik
A Mapnik tutorial
Starting with Python
Using XML and CSS
CartoCSS and PostGIS

Any map design built up using Python objects should also be representable using XML. For completeness, here are the XML files corresponding to our previous exercises:

110-background.xml

Mapnik tutorial 010-background.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'/>

120-points.xml

Mapnik tutorial 020-points.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'>
  <Style name='basic_style'>     
    <Rule>
      <PointSymbolizer/>         
    </Rule>
  </Style>
  <Layer name='main_map'>
    <StyleName>basic_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-places.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
</Map>

121-points-images.xml

Mapnik tutorial 021-points-images.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'>
  <Style name='basic_style'>
    <Rule>
      <PointSymbolizer file='circle_red_16x16.png'/>
    </Rule>
  </Style>
  <Layer name='main_map'>
    <StyleName>basic_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-places.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
</Map>

130-lines.xml

Mapnik tutorial 030-lines.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'>
  <Style name='basic_style'>
    <Rule>
      <LineSymbolizer/>
    </Rule>
  </Style>
  <Layer name='main_map'>
    <StyleName>basic_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-roads.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
</Map>

131-lines-colour.xml

Mapnik tutorial 031-lines-colour.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'>
  <Style name='basic_style'>
    <Rule>
      <LineSymbolizer stroke='green' stroke-width='2'/>
    </Rule>
  </Style>
  <Layer name='main_map'>
    <StyleName>basic_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-roads.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
</Map>

132-lines-stroke.xml

Mapnik tutorial 032-lines-stroke.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'>
  <Style name='basic_style'>
    <Rule>
      <LineSymbolizer stroke='green' stroke-width='2' stroke-dasharray='6, 2'/>
    </Rule>
  </Style>
  <Layer name='main_map'>
    <StyleName>basic_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-roads.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
</Map>

140-layers.xml

Mapnik tutorial 040-layers.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'>
  <Style name='line_style'>
    <Rule>
      <LineSymbolizer/>
    </Rule>
  </Style>
  <Style name='point_style'>
    <Rule>
      <PointSymbolizer file='circle_red_16x16.png'/>
    </Rule>
  </Style>
  <Layer name='line_layer'>
    <StyleName>line_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-roads.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
  <Layer name='point_layer'>
    <StyleName>point_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-places.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
</Map>

150-filters.xml

Mapnik tutorial 050-filters.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'>
  <Style name='line_style'>
    <Rule>
      <Filter>[type]='rail'</Filter>
      <LineSymbolizer stroke-width='2' stroke-dasharray='6, 2'/>
    </Rule>
    <Rule>
      <Filter>[type]='road'</Filter>
      <LineSymbolizer/>
    </Rule>
    <Rule>
      <Filter>[type]='mainroad'</Filter>
      <LineSymbolizer stroke-width='2'/>
    </Rule>
    <Rule>
      <Filter>[type]='motorway'</Filter>
      <LineSymbolizer stroke='lightblue' stroke-width='4'/>
    </Rule>
  </Style>
  <Style name='point_style'>
    <Rule>
      <Filter>[type]='town'</Filter>
      <PointSymbolizer file='circle_red_8x8.png'/>
    </Rule>
    <Rule>
      <Filter>[type]='city'</Filter>
      <PointSymbolizer file='circle_red_16x16.png'/>
    </Rule>
  </Style>
  <Layer name='line_layer'>
    <StyleName>line_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-roads.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
  <Layer name='point_layer'>
    <StyleName>point_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-places.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
</Map>

160-text.xml

Mapnik tutorial 060-text.png
<?xml version='1.0'?>
<Map background-color='ghostwhite'>
  <Style name='line_style'>
    <Rule>
      <Filter>[type]='rail'</Filter>
      <LineSymbolizer stroke-width='2' stroke-dasharray='6, 2'/>
    </Rule>
    <Rule>
      <Filter>[type]='road'</Filter>
      <LineSymbolizer/>
      <TextSymbolizer face-name='DejaVu Sans Book' halo-radius='2' placement='line'>[name]</TextSymbolizer>
    </Rule>
    <Rule>
      <Filter>[type]='mainroad'</Filter>
      <LineSymbolizer stroke-width='2'/>
      <TextSymbolizer face-name='DejaVu Sans Book' halo-radius='2' placement='line'>[name]</TextSymbolizer>
    </Rule>
    <Rule>
      <Filter>[type]='motorway'</Filter>
      <LineSymbolizer stroke='lightblue' stroke-width='4'/>
      <TextSymbolizer face-name='DejaVu Sans Book' halo-radius='2' placement='line'>[name]</TextSymbolizer>
    </Rule>
  </Style>
  <Style name='point_style'>
    <Rule>
      <Filter>[type]='town'</Filter>
      <PointSymbolizer file='circle_red_8x8.png'/>
      <TextSymbolizer face-name='DejaVu Sans Book' halo-radius='3' dy='7'>[name]</TextSymbolizer>
    </Rule>
    <Rule>
      <Filter>[type]='city'</Filter>
      <PointSymbolizer file='circle_red_16x16.png'/>
      <TextSymbolizer face-name='DejaVu Sans Book' size='12' fill='red' halo-radius='3' dy='11'>[name]</TextSymbolizer>
    </Rule>
  </Style>
  <Layer name='line_layer'>
    <StyleName>line_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-roads.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
  <Layer name='point_layer'>
    <StyleName>point_style</StyleName>
    <Datasource>
      <Parameter name='file'>data-places.csv</Parameter>
      <Parameter name='type'>csv</Parameter>
    </Datasource>
  </Layer>
</Map>