2 Feature: Import with custom styles by osm2pgsql
3 Tests for the example customizations given in the documentation.
5 Scenario: Custom main tags (set new ones)
6 Given the lua style file
8 local flex = require('import-full')
11 boundary = {administrative = 'named'},
12 highway = {'always', street_lamp = 'named'},
18 n10 Tboundary=administrative x0 y0
19 n11 Tboundary=administrative,name=Foo x0 y0
20 n12 Tboundary=electoral x0 y0
21 n13 Thighway=primary x0 y0
22 n14 Thighway=street_lamp x0 y0
23 n15 Thighway=primary,landuse=street x0 y0
25 Then place contains exactly
26 | object | class | type |
27 | N11 | boundary | administrative |
28 | N13 | highway | primary |
29 | N15 | highway | primary |
31 Scenario: Custom main tags (modify existing)
32 Given the lua style file
34 local flex = require('import-full')
36 flex.modify_main_tags{
37 amenity = {prison = 'delete'},
38 highway = {stop = 'named'},
44 n10 Tamenity=hotel x0 y0
45 n11 Tamenity=prison x0 y0
46 n12 Thighway=stop x0 y0
47 n13 Thighway=stop,name=BigStop x0 y0
48 n14 Thighway=give_way x0 y0
49 n15 Thighway=bus_stop x0 y0
50 n16 Taeroway=no,name=foo x0 y0
51 n17 Taeroway=taxiway,name=D15 x0 y0
53 Then place contains exactly
54 | object | class | type |
55 | N10 | amenity | hotel |
56 | N13 | highway | stop |
57 | N15 | highway | bus_stop |
58 | N17 | aeroway | taxiway |
60 Scenario: Prefiltering tags
61 Given the lua style file
63 local flex = require('import-full')
66 delete_keys = {'source', 'source:*'},
67 extra_tags = {amenity = {'yes', 'no'}}
77 n2 Tamenity=hospital,source=survey x3 y6
78 n3 Ttourism=hotel,amenity=yes x0 y0
79 n4 Ttourism=hotel,amenity=telephone x0 y0
81 Then place contains exactly
82 | object | extratags |
84 | N3:tourism | 'amenity': 'yes' |
88 Scenario: Ignore some tags
89 Given the lua style file
91 local flex = require('import-extratags')
93 flex.ignore_keys{'ref:*', 'surface'}
97 n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
99 Then place contains exactly
100 | object | name | extratags |
101 | N100 | 'ref' : '34' | 'extra': '1' |
104 Scenario: Add for extratags
105 Given the lua style file
107 local flex = require('import-full')
109 flex.add_for_extratags{'ref:*', 'surface'}
111 When loading osm data
113 n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
115 Then place contains exactly
116 | object | name | extratags |
117 | N100 | 'ref' : '34' | 'ref:bodo': '34', 'surface': 'gray' |
121 Given the lua style file
123 local flex = require('flex-base')
125 flex.set_main_tags{highway = {traffic_light = 'named'}}
126 flex.set_name_tags{main = {'name', 'name:*'},
130 When loading osm data
132 n1 Thighway=stop,name=Something x0 y0
133 n2 Thighway=traffic_light,ref=453-4 x0 y0
134 n3 Thighway=traffic_light,name=Greens x0 y0
135 n4 Thighway=traffic_light,name=Red,ref=45 x0 y0
137 Then place contains exactly
139 | N3:highway | 'name': 'Greens' |
140 | N4:highway | 'name': 'Red', 'ref': '45' |
142 Scenario: Modify name tags
143 Given the lua style file
145 local flex = require('import-full')
147 flex.modify_name_tags{house = {}, extra = {'o'}}
149 When loading osm data
151 n1 Ttourism=hotel,ref=45,o=good
152 n2 Taddr:housename=Old,addr:street=Away
154 Then place contains exactly
156 | N1:tourism | 'o': 'good' |
158 Scenario: Address tags
159 Given the lua style file
161 local flex = require('import-full')
163 flex.set_address_tags{
164 main = {'addr:housenumber'},
166 postcode = {'postal_code', 'postcode', 'addr:postcode'},
167 country = {'country-code', 'ISO3166-1'}
170 When loading osm data
172 n1 Ttourism=hotel,addr:street=Foo x0 y0
173 n2 Taddr:housenumber=23,addr:street=Budd,postal_code=5567 x0 y0
174 n3 Taddr:street=None,addr:city=Where x0 y0
176 Then place contains exactly
177 | object | type | address |
178 | N1:tourism | hotel | 'street': 'Foo' |
179 | N2:place | house | 'housenumber': '23', 'street': 'Budd', 'postcode': '5567' |
181 Scenario: Modify address tags
182 Given the lua style file
184 local flex = require('import-full')
186 flex.set_address_tags{
190 When loading osm data
192 n2 Taddr:housenumber=23,addr:street=Budd,is_in:city=Faraway,postal_code=5567 x0 y0
194 Then place contains exactly
195 | object | type | address |
196 | N2:place | house | 'housenumber': '23', 'street': 'Budd', 'postcode': '5567' |
198 Scenario: Unused handling (delete)
199 Given the lua style file
201 local flex = require('import-full')
203 flex.set_address_tags{
204 main = {'addr:housenumber'},
205 extra = {'addr:*', 'tiger:county'}
207 flex.set_unused_handling{delete_keys = {'tiger:*'}}
209 When loading osm data
211 n1 Ttourism=hotel,tiger:county=Fargo x0 y0
212 n2 Ttourism=hotel,tiger:xxd=56,else=other x0 y0
214 Then place contains exactly
215 | object | type | address | extratags |
216 | N1:tourism | hotel | 'tiger:county': 'Fargo' | - |
217 | N2:tourism | hotel | - | 'else': 'other' |
219 Scenario: Unused handling (extra)
220 Given the lua style file
222 local flex = require('flex-base')
223 flex.set_main_tags{highway = 'always',
225 flex.add_for_extratags{'wikipedia:*', 'wikidata'}
226 flex.set_unused_handling{extra_keys = {'surface'}}
228 When loading osm data
230 n100 Thighway=path,foo=bar,wikipedia=en:Path x0 y0
231 n234 Thighway=path,surface=rough x0 y0
232 n445 Thighway=path,name=something x0 y0
233 n446 Thighway=path,wikipedia:en=Path,wikidata=Q23 x0 y0
234 n567 Thighway=path,surface=dirt,wikipedia:en=Path x0 y0
236 Then place contains exactly
237 | object | type | extratags |
238 | N100:highway | path | 'wikipedia': 'en:Path' |
239 | N234:highway | path | 'surface': 'rough' |
240 | N445:highway | path | - |
241 | N446:highway | path | 'wikipedia:en': 'Path', 'wikidata': 'Q23' |
242 | N567:highway | path | 'surface': 'dirt', 'wikipedia:en': 'Path' |
244 Scenario: Additional relation types
245 Given the lua style file
247 local flex = require('import-full')
249 flex.RELATION_TYPES['site'] = flex.relation_as_multipolygon
254 When loading osm data
261 r1 Ttype=multipolygon,amenity=school Mw1@
262 r2 Ttype=site,amenity=school Mw1@
264 Then place contains exactly
266 | R1:amenity | school |
267 | R2:amenity | school |
269 Scenario: Exclude country relations
270 Given the lua style file
272 local flex = require('import-full')
274 function osm2pgsql.process_relation(object)
275 if object.tags.boundary ~= 'administrative' or object.tags.admin_level ~= '2' then
276 flex.process_relation(object)
283 When loading osm data
290 r1 Ttype=multipolygon,boundary=administrative,admin_level=4,name=Small Mw1@
291 r2 Ttype=multipolygon,boundary=administrative,admin_level=2,name=Big Mw1@
293 Then place contains exactly
295 | R1:boundary | administrative |
297 Scenario: Customize processing functions
298 Given the lua style file
300 local flex = require('import-full')
302 local original_process_tags = flex.process_tags
304 function flex.process_tags(o)
305 if o.object.tags.highway ~= nil and o.object.tags.access == 'no' then
309 original_process_tags(o)
312 When loading osm data
314 n1 Thighway=residential x0 y0
315 n2 Thighway=residential,access=no x0 y0
317 Then place contains exactly
319 | N1:highway | residential |