HikingBikingMaps/HillShading

From OpenStreetMap Wiki
Jump to: navigation, search

This page gives technical details for implementing the hill shading described at HikingBikingMaps.

The layer definition

<Layer name="dem" status="on">
	<StyleName>raster</StyleName>
	<Datasource>
		<Parameter name="type">gdal</Parameter>
		<Parameter name="file">rasterfilename including absolute path</Parameter>
		<Parameter name="format">tiff</Parameter>
	</Datasource>
</Layer>

should be inserted before the other layers, to be rendered below all others. Note that there is no srs definition for this layer. Layers have to have the projection of the rendered map anyway, and specifying a projection can even result in the layer not being rendered at all. The style part then is simply

<Style name="raster">
	<Rule>
		<RasterSymbolizer>
		</RasterSymbolizer>
	</Rule>
</Style>

Unfortunately, this is not yet all. There are a lot of other layers, which now cover the included raster images. Depending on the desired look, at least some of them must be made (partly) transparent. The example image at the top modifies some of the existing styles as follows (find the appropriate lines to change by the matching "<Style name=...>" and "<Filter>...</Filter>" lines), to render the background, woods/forests, and residential areas partly transparently.

   <Style name="world-1">
    <Rule>
      <MaxScaleDenominator>250000000000</MaxScaleDenominator>
      <MinScaleDenominator>6000000</MinScaleDenominator>
      <PolygonSymbolizer>
        <CssParameter name="fill">#fd0</CssParameter>
        <CssParameter name="fill-opacity">0.2</CssParameter>
      </PolygonSymbolizer>
       <LineSymbolizer>
        <CssParameter name="stroke">#b5d0d0</CssParameter>
        <CssParameter name="stroke-width">0.5</CssParameter>
      </LineSymbolizer>
    </Rule>
  </Style>
  <Style name="world">
    <Rule>
      <MaxScaleDenominator>6000000</MaxScaleDenominator>
      <MinScaleDenominator>600000</MinScaleDenominator>
      <PolygonSymbolizer>
        <CssParameter name="fill">#fd0</CssParameter>
        <CssParameter name="fill-opacity">0.2</CssParameter>
      </PolygonSymbolizer>
    </Rule>
  </Style>
  <Style name="coast-poly">
    <Rule>
      <MaxScaleDenominator>600000</MaxScaleDenominator>
      <PolygonSymbolizer>
        <CssParameter name="fill">#fd0</CssParameter>
        <CssParameter name="fill-opacity">0.2</CssParameter>
      </PolygonSymbolizer>
    </Rule>
  </Style>
    <Rule>
      <Filter>[landuse] = 'forest' and not [natural] = 'wood'</Filter>
      <MaxScaleDenominator>2000000</MaxScaleDenominator>
      <MinScaleDenominator>50000</MinScaleDenominator>
      <PolygonSymbolizer>
        <CssParameter name="fill">#8dc56c</CssParameter>
        <CssParameter name="fill-opacity">0.4</CssParameter>
     </PolygonSymbolizer>
     <LineSymbolizer>
        <CssParameter name="stroke">#cfb</CssParameter>
        <CssParameter name="stroke-width">0.3</CssParameter>
     </LineSymbolizer>
    </Rule>
    <Rule>
      <Filter>[landuse] = 'forest' and not [natural] = 'wood'</Filter>
      <MaxScaleDenominator>50000</MaxScaleDenominator>
      <PolygonPatternSymbolizer file="svnmapnik/symbols/forest_transparent.png" type="png" width="21" height="24"/>
     <LineSymbolizer>
        <CssParameter name="stroke">#cfb</CssParameter>
        <CssParameter name="stroke-width">0.3</CssParameter>
     </LineSymbolizer>
    </Rule>
     <Rule>
      <Filter>[natural] = 'wood' or [landuse] = 'wood'</Filter>
      <MaxScaleDenominator>2000000</MaxScaleDenominator>
      <MinScaleDenominator>50000</MinScaleDenominator>
      <PolygonSymbolizer>
        <CssParameter name="fill">#8dc56c</CssParameter>
        <CssParameter name="fill-opacity">0.4</CssParameter>
     </PolygonSymbolizer>
     <LineSymbolizer>
        <CssParameter name="stroke">#cfb</CssParameter>
        <CssParameter name="stroke-width">0.3</CssParameter>
     </LineSymbolizer>
    </Rule>
    <Rule>
      <Filter>[landuse] = 'wood' or [natural] = 'wood'</Filter>
      <MaxScaleDenominator>50000</MaxScaleDenominator>
      <PolygonPatternSymbolizer file="svnmapnik/symbols/forest_transparent.png" type="png" width="21" height="24"/>
     <LineSymbolizer>
        <CssParameter name="stroke">#cfb</CssParameter>
        <CssParameter name="stroke-width">0.3</CssParameter>
     </LineSymbolizer>
    </Rule>
    <Rule>
      <MaxScaleDenominator>1000000</MaxScaleDenominator>
      <MinScaleDenominator>1000</MinScaleDenominator>
      <Filter>[landuse] = 'residential'</Filter>
      <PolygonSymbolizer>
        <CssParameter name="fill">#eee</CssParameter>
        <CssParameter name="fill-opacity">0.3</CssParameter>
      </PolygonSymbolizer>
     <LineSymbolizer>
        <CssParameter name="stroke">#e8e8e8</CssParameter>
        <CssParameter name="stroke-width">0.6</CssParameter>
     </LineSymbolizer>
    </Rule>

You will notice, that I am using a non-standard icon in these styles. I modified the existing svnmapnik/symbols/forest.png icon by setting the green background to be partially transparent (e.g. using gimp or another image processing application) and saved the result to svnmapnik/symbols/forest_transparent.png.