File: process-example.lua

package info (click to toggle)
tilemaker 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 78,284 kB
  • sloc: cpp: 28,715; ansic: 4,052; makefile: 180; ruby: 77; sh: 6
file content (105 lines) | stat: -rw-r--r-- 2,742 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--[[

	A simple example tilemaker configuration, intended to illustrate how it
	works and to act as a starting point for your own configurations.

	The basic principle is:
	- read OSM tags with Find(key)
	- write to vector tile layers with Layer(layer_name)
	- add attributes with Attribute(field, value)

	(This is a very basic subset of the OpenMapTiles schema. Don't take much 
	notice of the "class" attribute, that's an OMT implementation thing which 
	is just here to get them to show up with the default style.)

	It doesn't do much filtering by zoom level - all the roads appear all the
	time. If you want a practice project, try fixing that!

	You can view your output with tilemaker-server:

	tilemaker-server /path/to/your.mbtiles --static server/static

]]--


-- Nodes will only be processed if one of these keys is present

node_keys = { "amenity", "historic", "leisure", "place", "shop", "tourism" }


-- Assign nodes to a layer, and set attributes, based on OSM tags

function node_function(node)
	-- POIs go to a "poi" layer (we just look for amenity and shop here)
	local amenity = Find("amenity")
	local shop = Find("shop")
	if amenity~="" or shop~="" then
		Layer("poi")
		if amenity~="" then Attribute("class",amenity)
		else Attribute("class",shop) end
		Attribute("name:latin", Find("name"))
		AttributeNumeric("rank", 3)
	end
	
	-- Places go to a "place" layer
	local place = Find("place")
	if place~="" then
		Layer("place")
		Attribute("class", place)
		Attribute("name:latin", Find("name"))
		if place=="city" then
			AttributeNumeric("rank", 4)
			MinZoom(3)
		elseif place=="town" then
			AttributeNumeric("rank", 6)
			MinZoom(6)
		else
			AttributeNumeric("rank", 9)
			MinZoom(10)
		end
	end
end


-- Assign ways to a layer, and set attributes, based on OSM tags

function way_function()
	local highway  = Find("highway")
	local waterway = Find("waterway")
	local building = Find("building")

	-- Roads
	if highway~="" then
		Layer("transportation", false)
		if highway=="unclassified" or highway=="residential" then highway="minor" end
		Attribute("class", highway)
		-- ...and road names
		local name = Find("name")
		if name~="" then
			Layer("transportation_name", false)
			Attribute("class", highway)
			Attribute("name:latin", name)
		end
	end

	-- Rivers
	if waterway=="stream" or waterway=="river" or waterway=="canal" then
		Layer("waterway", false)
		Attribute("class", waterway)
		AttributeNumeric("intermittent", 0)
	end

	-- Lakes and other water polygons
	if Find("natural")=="water" then
		Layer("water", true)
		if Find("water")=="river" then
			Attribute("class", "river")
		else
			Attribute("class", "lake")
		end
	end
	-- Buildings
	if building~="" then
		Layer("building", true)
	end
end