Filling contour lines (contour "fills") (solved, found script)

Greetings.

Contour lines are designed only to be displayed as “line”, but is it possible to fill areas that bordered by this lines?

I’m trying to get something like that:

This is my map. Rendered in Tilemill. Color background is raster SRTM data (no smoothing, you can see separate pixels) converted using this color map to get “steps” instead of gradient:

And shapefile vector contour lines over that raster. Looks quite ok, but I think it will be much better if this height “step” areas can be also drawn by renderer based on contour lines, without raster background. So I’m looking for “contour fills”, not lines. Is there something like that?

I can’t just apply “fill” to contour lines, because (1) they are not ordered by height, and (2) fill will be applied to area inside contour without cutting higher areas (in case of mountains) or lower areas (in case of depressions), so even if they would be ordered by height, it’s imposible just draw it over by over. I experimented with different “polygon-comp-op” and semi-transparent rendering, but I was not satisfied by result. So I needed to find way to make “multipolygons”. I tried to use Inkscape, vector grahic editor, to vectorize raster SRTM image in order to convert it to shapefiles, but I’m not sure if I’m doing right way.

So I’ve decided to ask you, maybe community already have solution of this problem. Or I can take advice from you.

Hello Roman,

although I have no solution for you, it seems to be more a Tilemill problem, or its successor MapBox Studio …
There is no direct issue with OSM, or yes?

So have you already asken on any contact channel dealing with mapbox products?

Or maybe http://gis.stackexchange.com is an appropriate place to ask?

It definitely not a tilemill/mapboxstudio problem. I’ll explain.

Look at screenshot above. There is a small mountain. We have 200m contour area and three small 225 contour areas inside. If we draw 200m-area first and then 225m-areas on top of it, all will be ok, similar as we see on screenshot. But contour lines are not ordered by height in shapefile. And it’s not tilemill (nor other renderer) job to order it. So if this lines in shapefile listed as 225m first and 220m after, so 225m areas will be drawn first and then, on top of this areas, big 200m area will be drawn and it cover them, so 225m areas disappear under 200m.

But ordering is not solution. Look at bottom of screenshot, there is two small 75m depressions and huge 100m area around them. Here we have opposite situation: If we even have contour lines ordered bottom-to-top in shapefile, drawing huge 100m area on top of two small 75m areas will cover them and they will disappear.

So only solution is do not draw whole areas bordered by contour lines, but try to make “multipolygons” which contain only areas that should be filled for defined height. According to this example, 200m-area should not contain 225m-areas so it will be not depended on draw order, because 200m and 225m and any other areas will not intersect. That’s what I need to reach.

So, I’ve seen gdal’s source code… I think I can write custom tool on the base of that code. When (and if) I do it, I’ll make an announcement.

Found solution here: http://geoexamples.blogspot.ru/2013/08/creating-vectorial-isobands-with-python.html

:slight_smile: