forked from abrensch/brouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrouter_cfg.lua
More file actions
210 lines (177 loc) · 6.29 KB
/
Copy pathbrouter_cfg.lua
File metadata and controls
210 lines (177 loc) · 6.29 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
-- special config to calcule pseudo-tags / "Brouter project"
local srid = 3857
-- 3857 (projection) SHOULD BE USED here for distance calculation ... (not srid = 4326 !)
-- https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-web-mapping
local tables = {}
tables.lines = osm2pgsql.define_way_table('lines', {
{ column = 'name', type = 'text' },
{ column = 'osm_id', type = 'text' },
{ column = 'highway', type = 'text' },
{ column = 'maxspeed', type = 'text' },
{ column = 'waterway', type = 'text' },
{ column = 'width', type = 'text' },
{ column = 'way', type = 'linestring', projection = srid, not_null = true },
})
tables.polygons = osm2pgsql.define_area_table('polygons', {
{ column = 'osm_id', type = 'text' },
{ column = 'type', type = 'text' },
{ column = 'boundary', type = 'text' },
{ column = 'name', type = 'text' },
{ column = 'place', type = 'text' },
{ column = 'population', type = 'text' },
{ column = 'landuse', type = 'text' },
{ column = 'leisure', type = 'text' },
{ column = 'natural', type = 'text' },
{ column = 'water', type = 'text' },
{ column = 'power', type = 'text' },
{ column = 'plant_method', type = 'text' },
{ column = 'plant_source', type = 'text' },
{ column = 'aeroway', type = 'text' },
{ column = 'aerodrome', type = 'text' },
{ column = 'way', type = 'geometry', projection = srid, not_null = true },
})
tables.cities = osm2pgsql.define_node_table('cities', {
{ column = 'name', type = 'text' },
{ column = 'place', type = 'text' },
{ column = 'admin_level', type = 'text' },
{ column = 'osm_id', type = 'text' },
{ column = 'population', type = 'text' },
{ column = 'way', type = 'geometry', projection = srid, not_null = true },
})
-- create a table for cities from special relation
tables.cities_rel = osm2pgsql.define_relation_table('cities_rel', {
{ column = 'reltype', type = 'text' },
{ column = 'admin_level', type = 'text' },
{ column = 'boundary', type = 'text' },
{ column = 'name', type = 'text' },
{ column = 'place', type = 'text' },
{ column = 'osm_id', type = 'text' },
{ column = 'population', type = 'text' },
{ column = 'way', type = 'geometry', projection = srid, not_null = true },
})
-- create a table for peaks from nodes
tables.peak = osm2pgsql.define_node_table('peak', {
{ column = 'name', type = 'text' },
{ column = 'natural', type = 'text' },
{ column = 'osm_id', type = 'text' },
{ column = 'ele', type = 'text' },
{ column = 'way', type = 'geometry', projection = srid, not_null = true },
})
-- Helper function that looks at the tags and decides if this is possibly
-- an area.
function has_area_tags(tags)
if tags.area == 'yes' then
return true
end
if tags.area == 'no' then
return false
end
return tags.place
or tags.population
end
function get_plant_source(tags)
local source = nil
for _, key in ipairs({'source'}) do
local a = tags['plant:' .. key]
if a then
source = a
end
end
return source
end
function get_plant_method(tags)
local method = nil
for _, key in ipairs({'method'}) do
local a = tags['plant:' .. key]
if a then
method = a
end
end
return method
end
function osm2pgsql.process_node(object)
if (object.tags.place == 'city' or object.tags.place == 'town' or object.tags.place == 'municipality') and has_area_tags(object.tags) then
tables.cities:insert({
osm_id = object.id,
name = object.tags.name,
place = object.tags.place,
admin_level = object.tags.admin_level,
population = object.tags.population,
way = object:as_point()
})
end
if (object.tags.natural == 'peak') then
tables.peak:insert({
natural = object.tags.natural,
name = object.tags.name,
ele = object.tags.ele,
osm_id = object.id,
way = object:as_point()
})
end
end
function osm2pgsql.process_way(object)
local way_type = object:grab_tag('type')
if ( object.tags.natural == 'water') or (object.tags.landuse ~= nil ) or (object.tags.leisure ~= nil ) then
tables.polygons:insert({
name = object.tags.name,
osm_id = object.id,
type = way_type,
landuse = object.tags.landuse,
leisure = object.tags.leisure,
natural = object.tags.natural,
water = object.tags.water,
power = object.tags.power,
plant_source = get_plant_source(object.tags),
plant_method = get_plant_method(object.tags),
aeroway = object.tags.aeroway,
aerodrome = object.tags.aerodrome,
way = object:as_polygon()
})
end
if ( object.tags.highway ~= nil) or ( object.tags.waterway ~= nil) then
tables.lines:insert({
name = object.tags.name,
osm_id = object.id,
highway = object.tags.highway,
waterway = object.tags.waterway,
width = object.tags.width,
maxspeed = object.tags.maxspeed,
way = object:as_linestring()
})
end
end
function osm2pgsql.process_relation(object)
local relation_type = object:grab_tag('type')
tables.polygons:insert({
osm_id = object.id,
type = relation_type,
boundary = object.tags.boundary,
name = object.tags.name,
place = object.tags.place,
population = object.tags.population,
landuse = object.tags.landuse,
leisure = object.tags.leisure,
natural = object.tags.natural,
water = object.tags.water,
power = object.tags.power,
plant_source = get_plant_source(object.tags),
plant_method = get_plant_method(object.tags),
aeroway = object.tags.aeroway,
aerodrome = object.tags.aerodrome,
way = object:as_multipolygon()
})
-- if (relation_type == 'boundary') and has_area_tags(object.tags) then
if (relation_type == 'boundary') then
tables.cities_rel:insert({
reltype = object.tags.relation_type,
boundary = object.tags.boundary,
admin_level = object.tags.admin_level,
name = object.tags.name,
place = object.tags.place,
population = object.tags.population,
osm_id = object.id,
way = object:as_multipolygon()
})
end
end