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

1
1

I would like to create a tile server in order to bulk download map tiles for personal use. I have followed the switch2osm guide and I managed to setup an OSM tile server with a small regional DB that works nicely.

However, I would also like to get contour lines on my tiles.

I have already read the information about SRTM, the contour lines and hill shading in the wiki, but it looks like an overly complicated process.

After looking around, I found that bbbike.org allows to extract regions of the map, and one of the options allows the extraction of SRTM data: http://extract.bbbike.org/

Here actually, they even have the entire planet SRTM pbf file available for download.

Can someone please explain how these data could be properly imported in the postgres database? Also, is there any further configuration that needs to be done in Mapnik or any other component?

asked 29 Mar '15, 23:49

cyberang3l's gravatar image

cyberang3l
56116
accept rate: 0%

edited 30 Mar '15, 14:19


I managed to import the data and configure them to appear on my map.

Steps I followed:

  1. This tutorial in order to setup a tile server: https://switch2osm.org/serving-tiles/building-a-tile-server-from-packages/
  2. On the "import map data" step, I extracted the part of the map I was interested from http://extract.bbbike.org/ (choose the format OSM -> Protocolbuffer (PBF)) and used this file for my database.
  3. At this point you should test that you have a working tile server, that is able to serve tiles if you visit http://ip.of.your.server/osm/0/0/0.png
  4. Now it is time to add the SRTM data. Go again to the website http://extract.bbbike.org/ and choose the same part of the map that chose when you extracted the database that you used on step 2. This time, choose the format "SRTM Europe PBF (25m)" if your extract is located in Europe, or "SRTM World PBF (40m)" if your extract is located anywhere else in the world. Download this file.
  5. Add the following lines at the end of the files /usr/share/osm2pgsql/default.style and /usr/share/osm2pgsql/osm2pgsql/default.style. These lines will force osm2pgsql in the next step to generate three additional table columns in the database, that are needed for the SRTM data. (probably you don't need to add the lines to both of the files, but I don't know which is the correct file so I added the lines to both of them and it worked)

     # Contour lines
     node,way    contour                 text    linear
     way         contour_ext             text    linear
     way         ele                     text    linear
 

  1. Append the SRTM data into the database with the command osm2pgsql --append --slim -d gis srtm-data.pbf

  2. Add the following XML text in the file /etc/mapnik-osm-carto-data/osm.xml, after the landcover-line Layer (around line 720 in the file).

    <layer name="srtm-minor" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"> <stylename>contours-minor</stylename> <datasource> <parameter name="type"><![CDATA[postgis]]></parameter> <parameter name="table"><![CDATA[(SELECT way,ele,ele as name FROM planet_osm_line WHERE contour_ext = 'elevation_minor') AS "contours-minor"]]></parameter> <parameter name="dbname"><![CDATA[gis]]></parameter> </datasource> </layer> <layer name="srtm-medium" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"> <stylename>contours-medium</stylename> <stylename>contours-medium-text</stylename> <datasource> <parameter name="type"><![CDATA[postgis]]></parameter> <parameter name="table"><![CDATA[(SELECT way,ele,ele as name FROM planet_osm_line WHERE contour_ext = 'elevation_medium') AS "contours-medium"]]></parameter> <parameter name="dbname"><![CDATA[gis]]></parameter> </datasource> </layer> <layer name="srtm-major" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"> <stylename>contours-major</stylename> <stylename>contours-major-text</stylename> <datasource> <parameter name="type"><![CDATA[postgis]]></parameter> <parameter name="table"><![CDATA[(SELECT way,ele,ele as name FROM planet_osm_line WHERE contour_ext = 'elevation_major') AS "contours-major"]]></parameter> <parameter name="dbname"><![CDATA[gis]]></parameter> </datasource> </layer>

    <style name="contours-minor"> <rule> <maxscaledenominator>70000</maxscaledenominator> <minscaledenominator>2000</minscaledenominator> <linesymbolizer stroke="#9cb197" stroke-width="0.3"/> </rule> </style> <style name="contours-medium"> <rule> <maxscaledenominator>300000</maxscaledenominator> <minscaledenominator>70000</minscaledenominator> <linesymbolizer stroke="#9cb197" stroke-width="0.5"/> </rule> <rule> <maxscaledenominator>70000</maxscaledenominator> <minscaledenominator>2000</minscaledenominator> <linesymbolizer stroke="#747b90" stroke-width="0.5"/> </rule> </style> <style name="contours-major"> <rule> <maxscaledenominator>600000</maxscaledenominator> <minscaledenominator>300000</minscaledenominator> <linesymbolizer stroke="#9cb197" stroke-width="0.7"/> </rule> <rule> <maxscaledenominator>300000</maxscaledenominator> <minscaledenominator>70000</minscaledenominator> <linesymbolizer stroke="#747b90" stroke-width="0.7"/> </rule> <rule> <maxscaledenominator>70000</maxscaledenominator> <minscaledenominator>2000</minscaledenominator> <linesymbolizer stroke="#855d62" stroke-width="0.7"/> </rule> </style> <style name="contours-medium-text"> <rule> <maxscaledenominator>70000</maxscaledenominator> <minscaledenominator>2000</minscaledenominator> <textsymbolizer size="10" fill="#9c9" fontset-name="fontset-1" halo-radius="1" wrap-width="14"><![CDATA[[name]]]></textsymbolizer> <textsymbolizer fontset-name="fontset-0" size="10" fill="#747b90" halo-radius="1" placement="line"><![CDATA[[ele]]]></textsymbolizer> </rule> </style> <style name="contours-major-text"> <rule> <maxscaledenominator>300000</maxscaledenominator> <minscaledenominator>70000</minscaledenominator> <textsymbolizer fontset-name="fontset-1" size="10" fill="#747b90" halo-radius="1" placement="line"><![CDATA[[ele]]]></textsymbolizer> </rule> <rule> <maxscaledenominator>70000</maxscaledenominator> <minscaledenominator>2000</minscaledenominator> <textsymbolizer fontset-name="fontset-1" size="10" fill="#855d62" halo-radius="1" placement="line"><![CDATA[[ele]]]></textsymbolizer> </rule> </style>

  3. Restart renderd, and you should have the contour lines shown on the map. Probably you will need to tune the osm.xml file, because I noticed that it gets bloated with the contour lines and the default style provided by osm.xml that already shows too many things on the map.

permanent link

answered 31 Mar '15, 02:04

cyberang3l's gravatar image

cyberang3l
56116
accept rate: 0%

wikified 31 Mar '15, 15:06

Does anyone know how to insert XML code properly in an answer?

(31 Mar '15, 02:05) cyberang3l

Also, how can I continue the list numbering after a code block? In the preview is was shown correctly, but now that I see the answer posted, after each code block the ordered lists start counting from 1 again.

(31 Mar '15, 02:08) cyberang3l
2

Nice answer. Welcome to markdown :-(

(31 Mar '15, 14:17) SK53 ♦
1

Alternatively you could present your solution in a blog entry via your OSM user account.

(31 Mar '15, 14:41) scai ♦

@scai: … where there is also Markdown, isn't it?

@cyberang3l: the "preview" does work partly. Use http://daringfireball.net/projects/markdown/dingus instead for previewing "complex" stuff. And http://daringfireball.net/projects/markdown/syntax should explain the formatting … however, I did not get the XML block to work, too.

(31 Mar '15, 15:04) aseerel4c26 ♦
2

For anyone interested, I collected a few different map styles and I made a script for easy installation in one go. One of the map styles is the OSM Bright map that includes contour lines. I didn't use the XML code above, but I incorporated the change in the CartoCSS.

You can check it out here: https://github.com/cyberang3l/osm-maps

(04 Apr '15, 00:56) cyberang3l
showing 5 of 6 show 1 more comments

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:

×36
×25
×10
×2

question asked: 29 Mar '15, 23:49

question was seen: 7,470 times

last updated: 04 Apr '15, 00:56

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