NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Can someone give an example? I am missing any OSM-specific docs around... I know I can download the real OpenStreetMap style but I do not really understand it. I am looking for a simpler example.

asked 22 Mar '12, 19:47

Kozuch's gravatar image

Kozuch
1.7k587285
accept rate: 8%

edited 22 Mar '12, 20:59

SomeoneElse's gravatar image

SomeoneElse ♦
36.9k71370866


Here is a simple example that I have taken from Jochen Topf's and my book, "OpenStreetMap - Using and Enhancing the Free Map of the World".

Suppose you have imported data with osm2pgsql, and you want to draw all roads (no matter what type of road) as a grey line. You would make a style like this:

<Style name="roads">
  <Rule>
    <LineSymbolizer>
      <CssParameter name="stroke">#aaa</CssParameter>
      <CssParameter name="stroke-width">0.4</CssParameter>
    </LineSymbolizer>
  </Rule>
</Style>

You will need a layer definition to go with that:

<Layer name="roads" status="on" srs="+init=epsg:4326">
  <StyleName>roads</StyleName>
  <Datasource>
    <Parameter name="table">
    (select way from planet_osm_line where highway is not null) as road
    </Parameter>
    <Parameter name="type">postgis</Parameter>
    <Parameter name="port">5432</Parameter>
    <Parameter name="user">osm</Parameter>
    <Parameter name="dbname">osm</Parameter>
    <Parameter name="estimate_extent">false</Parameter>
    <Parameter name="extent">-180,-85,180,85</Parameter>
  </Datasource>
</Layer>

This assumes that there is a database called “osm” on the local PostGIS server, that the user “osm” has access to it, and that it has a table named planet_osm_line, populated with geometry data in the EPSG:4326 projection, from which we can load information about roads. This is exactly what Osm2pgsql produces when you run it with the --latlong option.

The next thing you will want to do is of course have different rules for different types of roads (probably using the <filter> element), and maybe different rules styles for different zoom levels (using the <maxscaledenominator> and <minscaledenominator> elements).

See the Mapnik documentation at https://github.com/mapnik/mapnik/wiki/ for further details.

permanent link

answered 22 Mar '12, 21:00

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×440
×341
×24

question asked: 22 Mar '12, 19:47

question was seen: 6,188 times

last updated: 22 Mar '12, 21:00

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum