1 Feature: Import with custom styles by osm2pgsql
2 Tests for the example customizations given in the documentation.
4 Scenario: Custom main tags (set new ones)
5 Given the lua style file
7 local flex = require('import-full')
10 boundary = {administrative = 'named'},
11 highway = {'always', street_lamp = 'named'},
17 n10 Tboundary=administrative x0 y0
18 n11 Tboundary=administrative,name=Foo x0 y0
19 n12 Tboundary=electoral x0 y0
20 n13 Thighway=primary x0 y0
21 n14 Thighway=street_lamp x0 y0
22 n15 Thighway=primary,landuse=street x0 y0
24 Then place contains exactly
25 | object | class | type |
26 | N11 | boundary | administrative |
27 | N13 | highway | primary |
28 | N15 | highway | primary |
30 Scenario: Custom main tags (modify existing)
31 Given the lua style file
33 local flex = require('import-full')
35 flex.modify_main_tags{
36 amenity = {prison = 'delete'},
37 highway = {stop = 'named'},
43 n10 Tamenity=hotel x0 y0
44 n11 Tamenity=prison x0 y0
45 n12 Thighway=stop x0 y0
46 n13 Thighway=stop,name=BigStop x0 y0
47 n14 Thighway=give_way x0 y0
48 n15 Thighway=bus_stop x0 y0
49 n16 Taeroway=no,name=foo x0 y0
50 n17 Taeroway=taxiway,name=D15 x0 y0
52 Then place contains exactly
53 | object | class | type |
54 | N10 | amenity | hotel |
55 | N13 | highway | stop |
56 | N15 | highway | bus_stop |
57 | N17 | aeroway | taxiway |
59 Scenario: Prefiltering tags
60 Given the lua style file
62 local flex = require('import-full')
65 delete_keys = {'source', 'source:*'},
66 extra_tags = {amenity = {'yes', 'no'}}
76 n2 Tamenity=hospital,source=survey x3 y6
77 n3 Ttourism=hotel,amenity=yes x0 y0
78 n4 Ttourism=hotel,amenity=telephone x0 y0
80 Then place contains exactly
81 | object | class | extratags!dict |
83 | N3 | tourism | 'amenity': 'yes' |
87 Scenario: Ignore some tags
88 Given the lua style file
90 local flex = require('import-extratags')
92 flex.ignore_keys{'ref:*', 'surface'}
96 n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
98 Then place contains exactly
99 | object | name!dict | extratags!dict |
100 | N100 | 'ref' : '34' | 'extra': '1' |
103 Scenario: Add for extratags
104 Given the lua style file
106 local flex = require('import-full')
108 flex.add_for_extratags{'ref:*', 'surface'}
110 When loading osm data
112 n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
114 Then place contains exactly
115 | object | name!dict | extratags!dict |
116 | N100 | 'ref' : '34' | 'ref:bodo': '34', 'surface': 'gray' |
120 Given the lua style file
122 local flex = require('flex-base')
124 flex.set_main_tags{highway = {traffic_light = 'named'}}
125 flex.set_name_tags{main = {'name', 'name:*'},
129 When loading osm data
131 n1 Thighway=stop,name=Something x0 y0
132 n2 Thighway=traffic_light,ref=453-4 x0 y0
133 n3 Thighway=traffic_light,name=Greens x0 y0
134 n4 Thighway=traffic_light,name=Red,ref=45 x0 y0
136 Then place contains exactly
137 | object | class | name!dict |
138 | N3 | highway | 'name': 'Greens' |
139 | N4 | highway | 'name': 'Red', 'ref': '45' |
141 Scenario: Modify name tags
142 Given the lua style file
144 local flex = require('import-full')
146 flex.modify_name_tags{house = {}, extra = {'o'}}
148 When loading osm data
150 n1 Ttourism=hotel,ref=45,o=good
151 n2 Taddr:housename=Old,addr:street=Away
153 Then place contains exactly
154 | object | class | name!dict |
155 | N1 | tourism | 'o': 'good' |
157 Scenario: Address tags
158 Given the lua style file
160 local flex = require('import-full')
162 flex.set_address_tags{
163 main = {'addr:housenumber'},
165 postcode = {'postal_code', 'postcode', 'addr:postcode'},
166 country = {'country-code', 'ISO3166-1'}
169 When loading osm data
171 n1 Ttourism=hotel,addr:street=Foo x0 y0
172 n2 Taddr:housenumber=23,addr:street=Budd,postal_code=5567 x0 y0
173 n3 Taddr:street=None,addr:city=Where x0 y0
175 Then place contains exactly
176 | object | class | type | address!dict |
177 | N1 | tourism | hotel | 'street': 'Foo' |
178 | N2 | place | house | 'housenumber': '23', 'street': 'Budd', 'postcode': '5567' |
180 Scenario: Modify address tags
181 Given the lua style file
183 local flex = require('import-full')
185 flex.set_address_tags{
189 When loading osm data
191 n2 Taddr:housenumber=23,addr:street=Budd,is_in:city=Faraway,postal_code=5567 x0 y0
193 Then place contains exactly
194 | object | class | type | address!dict |
195 | N2 | place | house | 'housenumber': '23', 'street': 'Budd', 'postcode': '5567' |
197 Scenario: Unused handling (delete)
198 Given the lua style file
200 local flex = require('import-full')
202 flex.set_address_tags{
203 main = {'addr:housenumber'},
204 extra = {'addr:*', 'tiger:county'}
206 flex.set_unused_handling{delete_keys = {'tiger:*'}}
208 When loading osm data
210 n1 Ttourism=hotel,tiger:county=Fargo x0 y0
211 n2 Ttourism=hotel,tiger:xxd=56,else=other x0 y0
213 Then place contains exactly
214 | object | class | type | address!dict | extratags!dict |
215 | N1 | tourism | hotel | 'tiger:county': 'Fargo' | - |
216 | N2 | tourism | hotel | - | 'else': 'other' |
218 Scenario: Unused handling (extra)
219 Given the lua style file
221 local flex = require('flex-base')
222 flex.set_main_tags{highway = 'always',
224 flex.add_for_extratags{'wikipedia:*', 'wikidata'}
225 flex.set_unused_handling{extra_keys = {'surface'}}
227 When loading osm data
229 n100 Thighway=path,foo=bar,wikipedia=en:Path x0 y0
230 n234 Thighway=path,surface=rough x0 y0
231 n445 Thighway=path,name=something x0 y0
232 n446 Thighway=path,wikipedia:en=Path,wikidata=Q23 x0 y0
233 n567 Thighway=path,surface=dirt,wikipedia:en=Path x0 y0
235 Then place contains exactly
236 | object | class | type | extratags!dict |
237 | N100 | highway | path | 'wikipedia': 'en:Path' |
238 | N234 | highway | path | 'surface': 'rough' |
239 | N445 | highway | path | - |
240 | N446 | highway | path | 'wikipedia:en': 'Path', 'wikidata': 'Q23' |
241 | N567 | highway | path | 'surface': 'dirt', 'wikipedia:en': 'Path' |
243 Scenario: Additional relation types
244 Given the lua style file
246 local flex = require('import-full')
248 flex.RELATION_TYPES['site'] = flex.relation_as_multipolygon
253 When loading osm data
260 r1 Ttype=multipolygon,amenity=school Mw1@
261 r2 Ttype=site,amenity=school Mw1@
263 Then place contains exactly
264 | object | class | type |
265 | R1 | amenity | school |
266 | R2 | amenity | school |
268 Scenario: Exclude country relations
269 Given the lua style file
271 local flex = require('import-full')
273 function osm2pgsql.process_relation(object)
274 if object.tags.boundary ~= 'administrative' or object.tags.admin_level ~= '2' then
275 flex.process_relation(object)
282 When loading osm data
289 r1 Ttype=multipolygon,boundary=administrative,admin_level=4,name=Small Mw1@
290 r2 Ttype=multipolygon,boundary=administrative,admin_level=2,name=Big Mw1@
292 Then place contains exactly
293 | object | class | type |
294 | R1 | boundary | administrative |
296 Scenario: Customize processing functions
297 Given the lua style file
299 local flex = require('import-full')
301 local original_process_tags = flex.process_tags
303 function flex.process_tags(o)
304 if o.object.tags.highway ~= nil and o.object.tags.access == 'no' then
308 original_process_tags(o)
311 When loading osm data
313 n1 Thighway=residential x0 y0
314 n2 Thighway=residential,access=no x0 y0
316 Then place contains exactly
317 | object | class | type |
318 | N1 | highway | residential |