project.mml

changeset 0
b0eb3af2f9ee
child 2
8d4148a8ded4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project.mml	Mon Sep 14 22:55:45 2020 +0300
@@ -0,0 +1,804 @@
+scale: 1
+metatile: 2
+name: 
+description: A general-purpose OpenStreetMap mapnik style, in CartoCSS
+bounds: &world
+	- -180
+	- -85.05112877980659
+	- 180
+	- 85.05112877980659
+center:
+	- 0
+	- 0
+	- 4
+format: png
+interactivity: false
+minzoom: 0
+maxzoom: 22
+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"
+
+# Various parts to be included later on
+_parts:
+	# Extents are used for tilemill, and don't actually make it to the generated XML
+	extents: &extents
+		extent: *world
+		srs-name: "900913"
+		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"
+	osm2pgsql: &osm2pgsql
+		type: "postgis"
+		dbname: "gis"
+		key_field: ""
+		geometry_field: "way"
+		extent: "-20037508,-20037508,20037508,20037508"
+
+Stylesheet:
+	- style/style.mss
+	- style/roads.mss
+	- style/buildings.mss
+	- style/places.mss
+	- style/shapefiles.mss
+	- style/amenity.mss
+	- style/roadref.mss
+Layer:
+	- id: landcover
+		geometry: polygon
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					(CASE WHEN
+						"landuse" IN ('grass', 'meadow', 'recreation_ground')
+						OR ("leisure" IN ('park', 'playground', 'arena', 'stadium', 'sports_centre') AND landuse IS NULL)
+						OR "natural" = 'scrub'
+						THEN 'grass'
+						ELSE CASE WHEN ("landuse" IN ('commercial', 'retail') OR "amenity" IN ('bus_station', 'ferry_terminal'))
+							THEN 'commercial'
+							ELSE CASE WHEN ("natural" = 'wood' OR "landuse" = 'forest')
+								THEN 'forest'
+								ELSE CASE WHEN ("natural" = 'water' OR "landuse" IN ('reservoir'))
+									THEN 'water'
+									ELSE CASE WHEN ("landuse" IN ('religious', 'cemetery') OR "amenity" = 'grave_yard')
+										THEN 'religious'
+										ELSE CASE WHEN ("landuse" = 'railway')
+											THEN 'industrial'
+											ELSE "landuse"
+										END
+									END
+								END
+							END
+						END
+					END) AS feature,
+					way_area/NULLIF(POW(!scale_denominator!*0.001*0.28,2),0) AS way_pixels,
+					way_area
+					FROM planet_osm_polygon
+					WHERE (landuse IN ('forest', 'farmland', 'residential', 'commercial', 'retail', 'industrial', 'meadow', 'grass', 'vineyard', 'orchard', 'religious', 'railway', 'construction', 'cemetery')
+						OR "natural" IN ('wood', 'wetland', 'mud', 'sand', 'scree', 'shingle', 'bare_rock', 'heath', 'grassland', 'scrub', 'water'))
+						OR "leisure" IN ('park', 'playground', 'arena', 'stadium', 'sports_centre')
+						OR "amenity" IN ('bus_station', 'ferry_terminal', 'grave_yard')
+						AND way_area > 0.01*!pixel_width!::real*!pixel_height!::real
+						AND building IS NULL
+					ORDER BY way_area DESC, feature
+				) AS landcover
+		properties:
+			cache-features: true
+			minzoom: 5
+	- id: inland-water
+		geometry: polygon
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way
+					FROM planet_osm_polygon
+					WHERE ("natural" = 'water' OR landuse IN ('reservoir', 'basin') OR waterway = 'riverbank')
+				) AS landcover
+		properties:
+			cache-features: true
+			minzoom: 5
+	- id: ocean-lz
+		geometry: polygon
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+						way
+					FROM simplified_water_polygons
+				) AS ocean_lz
+		properties:
+			maxzoom: 9
+	- id: civic-services
+		geometry: polygon
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way
+					FROM planet_osm_polygon
+					WHERE ("amenity" IN ('hospital', 'community_centre', 'fire_station', 'school', 'university', 'kindergarten', 'childcare', 'social_facility') OR landuse IN ('civic_services', 'civic_admin'))
+				) AS civic_services
+		properties:
+			cache-features: true
+			minzoom: 5
+	- id: aerodrome
+		geometry: polygon
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way
+					FROM planet_osm_polygon
+					WHERE aeroway = 'aerodrome'
+				) AS aerodrome
+		properties:
+			minzoom: 10
+	- id: runway
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					aeroway,
+					ref
+					FROM planet_osm_line
+					WHERE aeroway IN ('runway', 'taxiway')
+				) AS aerodrome
+		properties:
+			minzoom: 10
+	- id: ocean
+		geometry: polygon
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+						way
+					FROM water_polygons
+				) AS ocean
+		properties:
+			minzoom: 10
+	- id: coastline
+		geometry: line
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT way FROM planet_osm_line WHERE "natural" = 'coastline') AS coastlines
+		properties:
+			minzoom: 12
+	- id: buildings
+		geometry: polygon
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					building
+					FROM planet_osm_polygon
+					WHERE building IS NOT NULL
+				) AS landcover
+		properties:
+			cache-features: true
+			minzoom: 14
+	- id: road-casing-low-zoom
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: &road_low_zoom_sql |-
+				(SELECT
+					way,
+					highway
+					FROM planet_osm_roads
+					WHERE "highway" IN ('primary', 'trunk')
+						AND (tags->"access" IS NULL OR tags->"access" NOT IN ('private', 'no'))
+					ORDER BY
+					CASE
+						WHEN highway = 'trunk' THEN 37
+						WHEN highway = 'primary' THEN 36
+					END ASC NULLS LAST
+				) AS road
+		properties:
+			minzoom: 4
+			maxzoom: 9
+	- id: road-low-zoom
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: *road_low_zoom_sql
+		properties:
+			minzoom: 4
+			maxzoom: 9
+	- id: road-casing-layer-n1
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: &road_sql |-
+				(SELECT
+					way,
+					(CASE WHEN "highway" IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')
+						THEN 'road_major'
+						ELSE CASE WHEN "highway" IN ('motorway_link', 'trunk_link', 'primary_link', 'secondary_link', 'tertiary_link', 'residential', 'unclassified', 'living_street')
+							THEN 'road_minor'
+							ELSE CASE WHEN "highway" IN ('path', 'footway', 'cycleway', 'track', 'steps', 'pedestrian', 'platform')
+								THEN 'road_path'
+								ELSE 'road_' || "highway"
+							END
+						END
+					END) AS feature,
+					name,
+					minority_name, 
+					highway,
+					COALESCE(layer::integer, 0) AS layer
+					FROM planet_osm_line
+					WHERE "highway" IS NOT NULL
+						AND (tags->"access" IS NULL OR tags->"access" NOT IN ('private', 'no'))
+					ORDER BY
+					CASE
+						WHEN highway = 'motorway' THEN 38
+						WHEN highway = 'trunk' THEN 37
+						WHEN highway = 'primary' THEN 36
+						WHEN highway = 'secondary' THEN 35
+						WHEN highway = 'tertiary' THEN 34
+						
+						WHEN highway = 'motorway_link' THEN 28
+						WHEN highway = 'trunk_link' THEN 27
+						WHEN highway = 'primary_link' THEN 26
+						WHEN highway = 'secondary_link' THEN 25
+						WHEN highway = 'tertiary_link' THEN 24
+						
+						WHEN highway = 'residential' THEN 10
+						WHEN highway = 'unclassified' THEN 10
+						WHEN highway = 'path' THEN 8
+						WHEN highway = 'footway' THEN 8
+						WHEN highway = 'cycleway' THEN 8
+						WHEN highway = 'service' THEN 5
+						
+						WHEN highway = 'runway' THEN 6
+						WHEN highway = 'taxiway' THEN 5
+					END ASC NULLS LAST
+				) AS road
+		properties:
+			minzoom: 10
+	- id: road-layer-n1
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: *road_sql
+		properties:
+			minzoom: 10
+	- id: rail-layer-n1
+		geometry: linestring
+		Datasource:
+			<<: *osm2pgsql
+			table: &rail_sql |-
+				(SELECT
+					way,
+					name,
+					minority_name,
+					service,
+					COALESCE(layer::integer, 0) AS layer,
+					tags->'electrified' AS electrified,
+					tags->'usage' AS usage
+					FROM planet_osm_line
+					WHERE "railway" = 'rail'
+					ORDER BY
+					CASE
+						WHEN service IS NULL THEN 20
+						WHEN service IS NOT NULL THEN 30
+					END DESC NULLS LAST
+				) AS rail
+	- id: road-casing
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: *road_sql
+		properties:
+			minzoom: 12
+	- id: road
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: *road_sql
+		properties:
+			minzoom: 12
+	- id: rail
+		geometry: linestring
+		Datasource:
+			<<: *osm2pgsql
+			table: *rail_sql
+	- id: bridge-area
+		geometry: polygon
+		Datasource:
+			<<: *osm2pgsql
+			table: &bridge_area_sql |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					'0' AS natural
+					FROM planet_osm_polygon
+					WHERE "man_made" = 'bridge'
+				) AS bridge_area
+		properties:
+			minzoom: 12
+	- id: road-casing-layer-1
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: *road_sql
+		properties:
+			minzoom: 12
+	- id: road-layer-1
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: *road_sql
+		properties:
+			minzoom: 12
+	- id: rail-layer-1
+		geometry: linestring
+		Datasource:
+			<<: *osm2pgsql
+			table: *rail_sql
+	- id: place-major
+		geometry: point
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					place
+					FROM planet_osm_point
+					WHERE "place" IN ('city', 'town')
+				) AS place_major
+		properties:
+			minzoom: 6
+			maxzoom: 15
+	- id: train-stations
+		geometry: point
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					railway,
+					tags->'railway:ref' AS ref
+					FROM planet_osm_point
+					WHERE "railway" IN ('station', 'halt')
+				) AS train_stations
+	- id: place-medium
+		geometry: point
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					place
+					FROM planet_osm_point
+					WHERE "place" IN ('suburb', 'borough', 'village')
+				) AS place_medium
+		properties:
+			minzoom: 12
+			maxzoom: 17
+	- id: stations
+		geometry: point
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					COALESCE(
+						'amenity_' || CASE WHEN amenity IN ('bus_station') THEN amenity END
+					) AS feature
+					FROM
+					(
+						SELECT
+						ST_PointOnSurface(way) AS way,
+							name,
+							bilingual_name,
+							amenity
+							FROM planet_osm_polygon
+							WHERE way && !bbox!
+								AND way_area < 768000*POW(!scale_denominator!*0.001*0.28,2)
+						UNION ALL
+						SELECT
+							way,
+							bilingual_name,
+							name,
+							amenity
+							FROM planet_osm_point
+							WHERE way && !bbox!
+					) AS station_subquery
+					WHERE (
+						"amenity" IN ('bus_station')
+					)
+				) AS stations
+		properties:
+			minzoom: 13
+	- id: place-natural
+		geometry: polygon
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					place,
+					way_area/NULLIF(POW(!scale_denominator!*0.001*0.28,2),0) AS way_pixels,
+					way_area
+					FROM planet_osm_polygon
+					WHERE (
+						"place" IN ('island', 'peninsula', 'isthmus', 'islet')
+						OR "natural" IN ('peak', 'hill', 'fell')
+					)
+				) AS place_natural
+		properties:
+			minzoom: 8
+	- id: place-minor
+		geometry: point
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					(CASE WHEN ("place" = 'locality' OR "natural" IN ('peak', 'hill', 'fell')) THEN 1 ELSE 0 END) AS natural
+					FROM planet_osm_point
+					WHERE (
+						"place" IN ('neighbourhood', 'quarter', 'farm', 'hamlet', 'locality')
+						OR "natural" IN ('peak', 'hill', 'fell')
+					)
+				) AS place_medium
+		properties:
+			minzoom: 15
+	- id: train-sites
+		geometry: point
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					railway,
+					tags->'railway:ref' AS ref
+					FROM planet_osm_point
+					WHERE "railway" IN ('site', 'yard', 'crossover', 'junction', 'technical_station', 'service_station')
+				) AS train_stations
+	- id: poi-name
+		geometry: polygon
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					0 as natural
+					FROM
+					(
+						SELECT
+						ST_PointOnSurface(way) AS way,
+							name,
+					bilingual_name,
+							man_made,
+							building,
+							leisure,
+							amenity,
+							historic
+							FROM planet_osm_polygon
+							WHERE way && !bbox!
+								AND way_area < 768000*POW(!scale_denominator!*0.001*0.28,2)
+						UNION ALL
+						SELECT
+							way,
+							name,
+					bilingual_name,
+							building,
+							man_made,
+							leisure,
+							amenity,
+							historic
+							FROM planet_osm_point
+							WHERE way && !bbox!
+					) AS poi_name_subquery
+					WHERE (
+						"man_made" IN ('bridge')
+						OR "amenity" IN ('hospital', 'university', 'exhibition_centre')
+						OR "leisure" IN ('stadium')
+						OR "historic" IN ('castle')
+					)
+				) AS poi_name
+		properties:
+			minzoom: 15
+	- id: poi-name-medium
+		geometry: polygon
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					shop,
+					0 as natural
+					FROM
+					(
+						SELECT
+						ST_PointOnSurface(way) AS way,
+							name,
+							bilingual_name,
+							amenity,
+							shop
+							FROM planet_osm_polygon
+							WHERE way && !bbox!
+								AND way_area < 768000*POW(!scale_denominator!*0.001*0.28,2)
+						UNION ALL
+						SELECT
+							way,
+							name,
+							bilingual_name,
+							shop,
+							amenity
+							FROM planet_osm_point
+							WHERE way && !bbox!
+					) AS poi_name_subquery
+					WHERE (
+						"amenity" IN ('school', 'marketplace', 'fire_station')
+						OR "shop" = 'mall'
+					)
+				) AS poi_name_medium
+		properties:
+			minzoom: 16
+	- id: aerodrome-name
+		geometry: point
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					aeroway,
+					name,
+					bilingual_name,
+					ref
+					FROM
+					(
+						SELECT
+						ST_PointOnSurface(way) AS way,
+							aeroway,
+							name,
+							bilingual_name,
+							COALESCE(tags->'iata', tags->'icao', ref) as ref
+							FROM planet_osm_polygon
+							WHERE way && !bbox!
+								AND way_area < 768000*POW(!scale_denominator!*0.001*0.28,2)
+						UNION ALL
+						SELECT
+							way,
+							aeroway,
+							name,
+							bilingual_name,
+							COALESCE(tags->'iata', tags->'icao', ref) as ref
+							FROM planet_osm_point
+							WHERE way && !bbox!
+					) AS station_subquery
+					WHERE "aeroway" = 'aerodrome'
+				) AS stations
+		properties:
+			minzoom: 9
+	
+	- id: poi-name-minor
+		geometry: polygon
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					name,
+					bilingual_name,
+					0 as natural
+					FROM
+					(
+						SELECT
+						ST_PointOnSurface(way) AS way,
+							name,
+							bilingual_name,
+							highway,
+							area,
+							amenity
+							FROM planet_osm_polygon
+							WHERE way && !bbox!
+								AND way_area < 768000*POW(!scale_denominator!*0.001*0.28,2)
+						UNION ALL
+						SELECT
+							way,
+							name,
+							bilingual_name,
+							highway,
+							NULL as area,
+							amenity
+							FROM planet_osm_point
+							WHERE way && !bbox!
+					) AS poi_name_subquery
+					WHERE (
+						"amenity" IN ('kindergarten', 'social_facility')
+						OR ("highway" IN ('footway', 'pedestrian') AND area = 'yes')
+					)
+				) AS poi_name_medium
+		properties:
+			minzoom: 17
+	- id: train-milestones
+		geometry: point
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					tags->'railway:position' AS position,
+					railway
+					FROM planet_osm_point
+					WHERE "railway" = 'milestone'
+				) AS train_milestones
+	- id: road-text
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: *road_sql
+		properties:
+			minzoom: 14
+	- id: road-text-minority
+		geometry: line
+		Datasource:
+			<<: *osm2pgsql
+			table: *road_sql
+		properties:
+			minzoom: 14
+	- id: roads-text-ref
+		geometry: linestring
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: &road-ref-sql |-
+				(SELECT
+						way,
+						highway,
+						refs,
+						ref_1,
+						ref_2,
+						ref_3,
+						ref_4,
+						ref_5,
+						ref_6,
+						ref_class_1,
+						ref_class_2,
+						ref_class_3,
+						ref_class_4,
+						ref_class_5,
+						ref_class_6,
+						ref_length_1,
+						ref_length_2,
+						ref_length_3,
+						ref_length_4,
+						ref_length_5,
+						ref_length_6
+					FROM (
+						SELECT
+								osm_id,
+								way,
+								highway,
+								array_to_string(refs, E'\n') AS refs,
+								refs[1] as ref_1,
+								refs[2] as ref_2,
+								refs[3] as ref_3,
+								refs[4] as ref_4,
+								refs[5] as ref_5,
+								refs[6] as ref_6,
+								ref_classes[1] as ref_class_1,
+								ref_classes[2] as ref_class_2,
+								ref_classes[3] as ref_class_3,
+								ref_classes[4] as ref_class_4,
+								ref_classes[5] as ref_class_5,
+								ref_classes[6] as ref_class_6,
+								ref_widths[1] as ref_length_1,
+								ref_widths[2] as ref_length_2,
+								ref_widths[3] as ref_length_3,
+								ref_widths[4] as ref_length_4,
+								ref_widths[5] as ref_length_5,
+								ref_widths[6] as ref_length_6
+							FROM (
+								SELECT
+										osm_id,
+										way,
+										highway,
+										string_to_array(ref, ';') AS refs,
+										string_to_array(ref_class, ';') AS ref_classes,
+										string_to_array(ref_width, ';') AS ref_widths
+									FROM planet_osm_line
+									WHERE (highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary'))
+										AND ref IS NOT NULL
+							) AS p) AS q
+					ORDER BY
+						CASE
+							WHEN highway = 'motorway' THEN 38
+							WHEN highway = 'trunk' THEN 37
+							WHEN highway = 'primary' THEN 36
+							WHEN highway = 'secondary' THEN 35
+							WHEN highway = 'tertiary' THEN 34
+							WHEN highway = 'taxiway' THEN 5
+						END DESC NULLS LAST,
+						refs,
+						osm_id
+				) AS roads_text_ref
+		properties:
+			minzoom: 8
+	- id: roads-text-ref2
+		geometry: linestring
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: *road-ref-sql
+		properties:
+			minzoom: 10
+	- id: roads-text-ref3
+		geometry: linestring
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: *road-ref-sql
+		properties:
+			minzoom: 10
+	- id: roads-text-ref4
+		geometry: linestring
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: *road-ref-sql
+		properties:
+			minzoom: 10
+	- id: roads-text-ref5
+		geometry: linestring
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: *road-ref-sql
+		properties:
+			minzoom: 10
+	- id: roads-text-ref6
+		geometry: linestring
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: *road-ref-sql
+		properties:
+			minzoom: 10
+	- id: railway-platform-ref
+		geometry: linestring
+		<<: *extents
+		Datasource:
+			<<: *osm2pgsql
+			table: |-
+				(SELECT
+					way,
+					COALESCE(tags->'local_ref', ref) AS ref
+					FROM planet_osm_line
+					WHERE "railway" = 'platform_edge'
+					ORDER BY ref
+				) AS railway_platform_edge_ref
+		properties:
+			minzoom: 17

mercurial