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 | categories |
82 | N2 | amenity | - | osm.amenity.hospital |
83 | N3 | tourism | 'amenity': 'yes' | osm.tourism.hotel |
84 | N4 | amenity | - | osm.tourism.hotel, osm.amenity.telephone |
86 Scenario: Ignore some tags
87 Given the lua style file
89 local flex = require('import-extratags')
91 flex.ignore_keys{'ref:*', 'surface'}
95 n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
97 Then place contains exactly
98 | object | name!dict | extratags!dict |
99 | N100 | 'ref' : '34' | 'extra': '1' |
102 Scenario: Add for extratags
103 Given the lua style file
105 local flex = require('import-full')
107 flex.add_for_extratags{'ref:*', 'surface'}
109 When loading osm data
111 n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
113 Then place contains exactly
114 | object | name!dict | extratags!dict |
115 | N100 | 'ref' : '34' | 'ref:bodo': '34', 'surface': 'gray' |
119 Given the lua style file
121 local flex = require('flex-base')
123 flex.set_main_tags{highway = {traffic_light = 'named'}}
124 flex.set_name_tags{main = {'name', 'name:*'},
128 When loading osm data
130 n1 Thighway=stop,name=Something x0 y0
131 n2 Thighway=traffic_light,ref=453-4 x0 y0
132 n3 Thighway=traffic_light,name=Greens x0 y0
133 n4 Thighway=traffic_light,name=Red,ref=45 x0 y0
135 Then place contains exactly
136 | object | class | name!dict |
137 | N3 | highway | 'name': 'Greens' |
138 | N4 | highway | 'name': 'Red', 'ref': '45' |
140 Scenario: Modify name tags
141 Given the lua style file
143 local flex = require('import-full')
145 flex.modify_name_tags{house = {}, extra = {'o'}}
147 When loading osm data
149 n1 Ttourism=hotel,ref=45,o=good
150 n2 Taddr:housename=Old,addr:street=Away
152 Then place contains exactly
153 | object | class | name!dict |
154 | N1 | tourism | 'o': 'good' |
156 Scenario: Address tags
157 Given the lua style file
159 local flex = require('import-full')
161 flex.set_address_tags{
162 main = {'addr:housenumber'},
164 postcode = {'postal_code', 'postcode', 'addr:postcode'},
165 country = {'country-code', 'ISO3166-1'}
168 When loading osm data
170 n1 Ttourism=hotel,addr:street=Foo x0 y0
171 n2 Taddr:housenumber=23,addr:street=Budd,postal_code=5567 x0 y0
172 n3 Taddr:street=None,addr:city=Where x0 y0
174 Then place contains exactly
175 | object | class | type | address!dict |
176 | N1 | tourism | hotel | 'street': 'Foo' |
177 | N2 | place | house | 'housenumber': '23', 'street': 'Budd', 'postcode': '5567' |
179 Scenario: Modify address tags
180 Given the lua style file
182 local flex = require('import-full')
184 flex.set_address_tags{
188 When loading osm data
190 n2 Taddr:housenumber=23,addr:street=Budd,is_in:city=Faraway,postal_code=5567 x0 y0
192 Then place contains exactly
193 | object | class | type | address!dict |
194 | N2 | place | house | 'housenumber': '23', 'street': 'Budd', 'postcode': '5567' |
196 Scenario: Unused handling (delete)
197 Given the lua style file
199 local flex = require('import-full')
201 flex.set_address_tags{
202 main = {'addr:housenumber'},
203 extra = {'addr:*', 'tiger:county'}
205 flex.set_unused_handling{delete_keys = {'tiger:*'}}
207 When loading osm data
209 n1 Ttourism=hotel,tiger:county=Fargo x0 y0
210 n2 Ttourism=hotel,tiger:xxd=56,else=other x0 y0
212 Then place contains exactly
213 | object | class | type | address!dict | extratags!dict |
214 | N1 | tourism | hotel | 'tiger:county': 'Fargo' | - |
215 | N2 | tourism | hotel | - | 'else': 'other' |
217 Scenario: Unused handling (extra)
218 Given the lua style file
220 local flex = require('flex-base')
221 flex.set_main_tags{highway = 'always',
223 flex.add_for_extratags{'wikipedia:*', 'wikidata'}
224 flex.set_unused_handling{extra_keys = {'surface'}}
226 When loading osm data
228 n100 Thighway=path,foo=bar,wikipedia=en:Path x0 y0
229 n234 Thighway=path,surface=rough x0 y0
230 n445 Thighway=path,name=something x0 y0
231 n446 Thighway=path,wikipedia:en=Path,wikidata=Q23 x0 y0
232 n567 Thighway=path,surface=dirt,wikipedia:en=Path x0 y0
234 Then place contains exactly
235 | object | class | type | extratags!dict |
236 | N100 | highway | path | 'wikipedia': 'en:Path' |
237 | N234 | highway | path | 'surface': 'rough' |
238 | N445 | highway | path | - |
239 | N446 | highway | path | 'wikipedia:en': 'Path', 'wikidata': 'Q23' |
240 | N567 | highway | path | 'surface': 'dirt', 'wikipedia:en': 'Path' |
242 Scenario: Additional relation types
243 Given the lua style file
245 local flex = require('import-full')
247 flex.RELATION_TYPES['site'] = flex.relation_as_multipolygon
252 When loading osm data
259 r1 Ttype=multipolygon,amenity=school Mw1@
260 r2 Ttype=site,amenity=school Mw1@
262 Then place contains exactly
263 | object | class | type |
264 | R1 | amenity | school |
265 | R2 | amenity | school |
267 Scenario: Exclude country relations
268 Given the lua style file
270 local flex = require('import-full')
272 function osm2pgsql.process_relation(object)
273 if object.tags.boundary ~= 'administrative' or object.tags.admin_level ~= '2' then
274 flex.process_relation(object)
281 When loading osm data
288 r1 Ttype=multipolygon,boundary=administrative,admin_level=4,name=Small Mw1@
289 r2 Ttype=multipolygon,boundary=administrative,admin_level=2,name=Big Mw1@
291 Then place contains exactly
292 | object | class | type |
293 | R1 | boundary | administrative |
295 Scenario: Customize processing functions
296 Given the lua style file
298 local flex = require('import-full')
300 local original_process_tags = flex.process_tags
302 function flex.process_tags(o)
303 if o.object.tags.highway ~= nil and o.object.tags.access == 'no' then
307 original_process_tags(o)
310 When loading osm data
312 n1 Thighway=residential x0 y0
313 n2 Thighway=residential,access=no x0 y0
315 Then place contains exactly
316 | object | class | type |
317 | N1 | highway | residential |