This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

mapnik + osm: how to generate contour map for state and counties

0

Hello,

I'm struggling to find info on how to generate maps with Mapnik (mml file) that only show the contour of states and counties for the US (for example), and everything else white or transparent.

Any pointer welcome. Thanks!

asked 07 Jul '21, 02:00

pat548's gravatar image

pat548
10113
accept rate: 0%

edited 07 Jul '21, 02:04

By contour do you mean height contours or just the administrative outlines?

(07 Jul '21, 20:37) InsertUser

I probably used the wrong word, I don't want height, just the country or state, or county, as a simple line, nothing else.

(09 Jul '21, 13:37) pat548

There is plenty of ways to achieve this. You should tell us a bit more about your goal, is it for a map on a website, is it for just a few counties, the all country? What have you tried so far?

(10 Jul '21, 09:43) yvecai

I just want to generate a PNG, with transparency, for either the whole US, with states, or a single state with counties. So far, I've tried modifying the project.mml file of the openstreetmap-carto project to only show those lines, but even with a single layer, it still show the ocean and there's no transparency:

Layer: - id: landcover-line geometry: linestring <<: extents Datasource: <<: osm2pgsql table: |- (SELECT way FROM planet_osm_line WHERE man_made = 'cutline' ) AS landcover_line properties: minzoom: 5

I guess my main problem is I can't find any good documentation about all the options I can use here. I've looked into the reference, but without examples, it's hard to follow.

(10 Jul '21, 14:23) pat548

Correction, the layer is actually:

Layer: - id: admin-low-zoom geometry: linestring <<: extents Datasource: <<: osm2pgsql table: |- (SELECT way, admin_level FROM planet_osm_roads WHERE boundary = 'administrative' AND admin_level IN ('0', '1', '2', '3', '4') AND osm_id < 0 ORDER BY admin_level DESC ) AS admin_low_zoom properties: minzoom: 4 maxzoom: 7

(10 Jul '21, 15:43) pat548

One Answer:

1

You have to set the background color of your map transparent, example in the xml:

In the style.mss, replace the @land-color by rgba(0,0,255,0)

Map {
  background-color: rgba(0,0,255,0);
}

At the end, the <map>tag in the xml generated should look like something like this:

<Map srs="..." background-color="rgba(0, 0, 255, 0)" > .. </Map>

answered 11 Jul '21, 17:20

yvecai's gravatar image

yvecai
1.5k1226
accept rate: 9%

Source code available on GitHub .