2

I want to make a map using Tilemill and I want to show the names of mountain-peaks.

What I'd like to do:

If the user zooms out (let's say zoom level 12) I only want to show the highest (most relevant) mountains in a certain area. If the user zooms in closer, I'd like to show more peaks.

The data I have is form an geofabrik import of OSM data into a postgres DB. I was hoping to find a tag like 'relevance' that I could use, but that doesn't seem to exist...

Is there a way to do that with OSM data alone?

3 Answers 3

2

The approach i've taken to this same problem was to show the 5 highest peaks in each tile at zooms < 14, and then show all above 14, which looks pretty good most of the time. This approach does assume that the content of the ele tag is valid, which it frequently is. If you need better elevations you could run some sort of script to lookup the elevations for all the points your interested in, and replace the OSM ele tags with that data.

Here is the sql I use for my "peak" layer in tilemill

  SELECT * FROM 
  (SELECT way, name,
   CASE WHEN ele~E'^[\\d\.]+$' THEN CAST(ele::float AS INTEGER) ELSE NULL END AS ele_meters,
   CASE WHEN ele~E'^[\\d\.]+$' THEN CAST(ele::float * 3.2808399 AS INTEGER) ELSE NULL END AS ele_feet
    FROM planet_osm_point
    WHERE 
    z(!scale_denominator!) > 6
    AND
    way && !bbox! 
    AND
    "natural"='peak' 
  ) AS intermediate 
  WHERE ele_meters IS NOT NULL
  ORDER BY ele_meters DESC 
  LIMIT ( CASE WHEN z(!scale_denominator!) >= 14 THEN 200 ELSE 5 END)
  ) AS data

Note that this query does omit any features that do not have a valid ele tag.

2
  • 1
    Sounds exactly like what I want!!! Awesome! The problem is that Tilemill tells me that it doesn't know z(numberic). So I looked into my DB and found a funtion st_z(geometry), st_zmax (box3d), st_zmflag (geometry) and st_zmin (box3d). But none that takes a numeric value... Can you tell me how to install the function z that you need into Postgres? Thanks a lot!
    – Georg
    Jul 10, 2014 at 5:59
  • Oh yeah, z, thats a custom function that converts a mapnik scale denominator to a zoom level, courtesy of mapbox, gist.github.com/JesseCrocker/f1130d63b7a37d3abc0a Jul 10, 2014 at 16:55
1

No, you cannot do that with OSM data alone. You will need additional information, like elevation data obtained from SRTM, and calculate the "relevance" of each peak for yourself.

4
  • do you have any suggestions on how i could do that? maybe and pointers to tutorials, or apps i can do that with?
    – Georg
    Jul 9, 2014 at 5:04
  • Sorry, I'm not very familiar with the rendering toolchain and the possibilities of spatial databases. I just know that this kind of information is not present in OSM and has to be computed by third-party tools.
    – scai
    Jul 9, 2014 at 7:44
  • That's not quite true - some peaks have the elevation as ele=... . Depends on the region, I think. Jul 17, 2014 at 13:19
  • Yes that's correct. What I wanted to say is that the peak's relevance is not contained in OSM and has to be computed outside. The height information is present for some peaks, but not for all of them. And for calculating the relevance of all peaks additional elevation data will be required.
    – scai
    Jul 17, 2014 at 14:25
0

I assume that you just need to create an appropriate filter in your style which should contain "ele" tag. For example:

layer[zoom>=12][zoom<=14][natural=peak] {

[ele>3500] { ... } }

layer[zoom>=15][zoom<=16] {

[ele>1500] { ... } }

This approach helps you separate all peaks by zoom levels. Note, that "ele" column contains string values. It means that before you need to convert it to a numeric value.

2
  • A possible solution, but a very static one. For some regions there will be no peaks visible at all because of their low average elevation, whereas for other regions there will be still too much peaks displayed.
    – scai
    Jul 9, 2014 at 7:42
  • yep... as my map covers a very big area, that would not work...
    – Georg
    Jul 9, 2014 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.