Phyghtmap/CartoCSS
This is an example of contours using Phyghtmap and CartoCSS, with following characteristics: - different colors of contours according elevation - different style for minor, medium and major contours - medium and major contours have a elevation label - contours at 0m are skipped
Add in carto the file contour.mss:
@contour-below: #886A08;
@contour-lowland: #0B3B0B;
@contour-highland: #3B240B;
@contour-veryhigh: #0B3B39;
#contours-minor {
line-width: 0.2;
[elevation < 0] {
line-color: @contour-below;
}
[elevation > 0][elevation < 2000] {
line-color: @contour-lowland;
}
[elevation >= 2000][elevation < 5000] {
line-color: @contour-highland;
}
[elevation >= 5000] {
line-color: @contour-veryhigh;
}
}
#contours-medium {
line-width: 0.4;
[elevation < 0] {
line-color: @contour-below;
}
[elevation > 0][elevation < 2000] {
line-color: @contour-lowland;
}
[elevation >= 2000][elevation < 5000] {
line-color: @contour-highland;
}
[elevation >= 5000] {
line-color: @contour-veryhigh;
}
}
#contours-major {
line-width: 0.6;
[elevation < 0] {
line-color: @contour-below;
}
[elevation > 0][elevation < 2000] {
line-color: @contour-lowland;
}
[elevation >= 2000][elevation < 5000] {
line-color: @contour-highland;
}
[elevation >= 5000] {
line-color: @contour-veryhigh;
}
}
#contours-medium-text {
text-name: "[ele]";
text-face-name: @book-fonts;
text-placement: line;
text-spacing: 500;
text-size: 7;
text-fill: #FF0000;
[elevation < 0] {
text-fill: @contour-below;
}
[elevation > 0][elevation < 2000] {
text-fill: @contour-lowland;
}
[elevation >= 2000][elevation < 5000] {
text-fill: @contour-highland;
}
[elevation >= 5000] {
text-fill: @contour-veryhigh;
}
}
#contours-major-text {
text-name: "[ele]";
text-face-name: @book-fonts;
text-placement: line;
text-spacing: 1000;
text-size: 8;
text-fill: #FF0000;
[elevation < 0] {
text-fill: @contour-below;
}
[elevation > 0][elevation < 2000] {
text-fill: @contour-lowland;
}
[elevation >= 2000][elevation < 5000] {
text-fill: @contour-highland;
}
[elevation >= 5000] {
text-fill: @contour-veryhigh;
}
}
Then in project.yaml, we should refer to the new file, in Stylesheet section:
- "contour.mss"
E.g. after - "ferry-routes.mss"
In the same file, we need to add dabatase access configuration:
osm2pgsql: &contour type: "postgis" user: "osmrender" dbname: "contours" key_field: "" geometry_field: "way" extent: "-20037508,-20037508,20037508,20037508"
After the section osm2pgsql: &osm2pgsql
In the same file: add the Layer section:
- id: "contours-minor"
name: "contours-minor"
class: ""
geometry: "linestring"
<<: *extents
Datasource:
<<: *contour
table: |-
(SELECT
way,
CAST (ele AS INTEGER) AS elevation,
ele
FROM planet_osm_line
WHERE contour_ext='elevation_minor'
) AS contours_minor
properties:
minzoom: 14
advanced: {}
- id: "contours-medium"
name: "contours-medium"
class: ""
geometry: "linestring"
<<: *extents
Datasource:
<<: *contour
table: |-
(SELECT
way,
CAST (ele AS INTEGER) AS elevation,
ele
FROM planet_osm_line
WHERE contour_ext='elevation_medium'
) AS contours_medium
properties:
minzoom: 12
advanced: {}
- id: "contours-major"
name: "contours-major"
class: ""
geometry: "linestring"
<<: *extents
Datasource:
<<: *contour
table: |-
(SELECT
way,
CAST (ele AS INTEGER) AS elevation,
ele
FROM planet_osm_line
WHERE contour_ext='elevation_major' AND ele != '0'
) AS contours_major
properties:
minzoom: 9
advanced: {}
- id: "contours-medium-text"
name: "contours-medium-text"
class: ""
geometry: "linestring"
<<: *extents
Datasource:
<<: *contour
table: |-
(SELECT
way,
CAST (ele AS INTEGER) AS elevation,
ele
FROM planet_osm_line
WHERE contour_ext='elevation_medium'
) AS contours_medium_text
properties:
minzoom: 13
advanced: {}
- id: "contours-major-text"
name: "contours-major-text"
class: ""
geometry: "linestring"
<<: *extents
Datasource:
<<: *contour
table: |-
(SELECT
way,
CAST (ele AS INTEGER) AS elevation,
ele
FROM planet_osm_line
WHERE contour_ext='elevation_major' AND ele != '0'
) AS contours_major_text
properties:
minzoom: 9
advanced: {}
A natural place could be just before id: "roads-text-ref". Note: Bottom layers are drawn on top of previous layers.