]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/osm2pgsql/import/custom_style.feature
405afdb5c4dc8c2d0c363e43439d64338c7ff0fe
[nominatim.git] / test / bdd / osm2pgsql / import / custom_style.feature
1 @DB
2 Feature: Import with custom styles by osm2pgsql
3     Tests for the example customizations given in the documentation.
4
5     Scenario: Custom main tags (set new ones)
6         Given the lua style file
7             """
8             local flex = require('import-full')
9
10             flex.set_main_tags{
11                 boundary = {administrative = 'named'},
12                 highway = {'always', street_lamp = 'named'},
13                 landuse = 'fallback'
14             }
15             """
16         When loading osm data
17             """
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
24             """
25         Then place contains exactly
26             | object | class    | type           |
27             | N11    | boundary | administrative |
28             | N13    | highway  | primary        |
29             | N15    | highway  | primary        |
30
31     Scenario: Custom main tags (modify existing)
32         Given the lua style file
33             """
34             local flex = require('import-full')
35
36             flex.add_main_tags{
37                 amenity = {prison = 'delete'},
38                 highway = {stop = 'named'},
39                 aeroway = 'named'
40             }
41             """
42         When loading osm data
43             """
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
52             """
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  |
59
60     Scenario: Prefiltering tags
61         Given the lua style file
62             """
63             local flex = require('import-full')
64
65             flex.set_prefilters{
66                 delete_keys = {'source', 'source:*'},
67                 extra_tags = {amenity = {'yes', 'no'}}
68             }
69             flex.set_main_tags{
70                 amenity = 'always',
71                 tourism = 'always'
72             }
73             """
74         When loading osm data
75             """
76             n1 Tamenity=yes x0 y6
77             n2 Tamenity=hospital,source=survey x3 y6
78             n3 Ttourism=hotel,amenity=yes x0 y0
79             n4 Ttourism=hotel,amenity=telephone x0 y0
80             """
81         Then place contains exactly
82             | object     | extratags              |
83             | N2:amenity | -                      |
84             | N3:tourism | 'amenity': 'yes'       |
85             | N4:tourism | - |
86             | N4:amenity | - |
87
88     Scenario: Ignore some tags
89         Given the lua style file
90             """
91             local flex = require('import-extratags')
92
93             flex.ignore_keys{'ref:*', 'surface'}
94             """
95         When loading osm data
96             """
97             n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
98             """
99         Then place contains exactly
100             | object | name         | extratags    |
101             | N100   | 'ref' : '34' | 'extra': '1' |
102
103
104     Scenario: Add for extratags
105         Given the lua style file
106             """
107             local flex = require('import-full')
108
109             flex.add_for_extratags{'ref:*', 'surface'}
110             """
111         When loading osm data
112             """
113             n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
114             """
115         Then place contains exactly
116             | object | name         | extratags    |
117             | N100   | 'ref' : '34' | 'ref:bodo': '34', 'surface': 'gray' |
118
119
120     Scenario: Name tags
121         Given the lua style file
122             """
123             local flex = require('flex-base')
124
125             flex.set_main_tags{highway = {traffic_light = 'named'}}
126             flex.set_name_tags{main = {'name', 'name:*'},
127                                extra = {'ref'}
128                               }
129             """
130         When loading osm data
131             """
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
136             """
137         Then place contains exactly
138             | object     | name                       |
139             | N3:highway | 'name': 'Greens'           |
140             | N4:highway | 'name': 'Red', 'ref': '45' |
141
142     Scenario: Modify name tags
143         Given the lua style file
144             """
145             local flex = require('import-full')
146
147             flex.modify_name_tags{house = {}, extra = {'o'}}
148             """
149         When loading osm data
150             """
151             n1 Ttourism=hotel,ref=45,o=good
152             n2 Taddr:housename=Old,addr:street=Away
153             """
154         Then place contains exactly
155             | object     | name        |
156             | N1:tourism | 'o': 'good' |
157
158     Scenario: Address tags
159         Given the lua style file
160             """
161             local flex = require('import-full')
162
163             flex.set_address_tags{
164                 main = {'addr:housenumber'},
165                 extra = {'addr:*'},
166                 postcode = {'postal_code', 'postcode', 'addr:postcode'},
167                 country = {'country-code', 'ISO3166-1'}
168             }
169             """
170         When loading osm data
171             """
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
175             """
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' |
180
181     Scenario: Modify address tags
182         Given the lua style file
183             """
184             local flex = require('import-full')
185
186             flex.set_address_tags{
187                 extra = {'addr:*'},
188             }
189             """
190         When loading osm data
191             """
192             n2 Taddr:housenumber=23,addr:street=Budd,is_in:city=Faraway,postal_code=5567 x0 y0
193             """
194         Then place contains exactly
195             | object     | type  | address |
196             | N2:place   | house | 'housenumber': '23', 'street': 'Budd', 'postcode': '5567' |
197
198     Scenario: Unused handling (delete)
199         Given the lua style file
200             """
201             local flex = require('import-full')
202
203             flex.set_address_tags{
204                 main = {'addr:housenumber'},
205                 extra = {'addr:*', 'tiger:county'}
206             }
207             flex.set_unused_handling{delete_keys = {'tiger:*'}}
208             """
209         When loading osm data
210             """
211             n1 Ttourism=hotel,tiger:county=Fargo x0 y0
212             n2 Ttourism=hotel,tiger:xxd=56,else=other x0 y0
213             """
214         Then place contains exactly
215             | object     | type  | address                 | extratags        |
216             | N1:tourism | hotel | 'tiger:county': 'Fargo' | -                |
217             | N2:tourism | hotel | -                       | 'else': 'other'  |
218
219     Scenario: Unused handling (extra)
220         Given the lua style file
221             """
222             local flex = require('flex-base')
223             flex.set_main_tags{highway = 'always',
224                                wikipedia = 'extra'}
225             flex.add_for_extratags{'wikipedia:*', 'wikidata'}
226             flex.set_unused_handling{extra_keys = {'surface'}}
227             """
228         When loading osm data
229             """
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
235             """
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' |
243
244     Scenario: Additional relation types
245         Given the lua style file
246             """
247             local flex = require('import-full')
248
249             flex.RELATION_TYPES['site'] = flex.relation_as_multipolygon
250             """
251         And the grid
252             | 1 | 2 |
253             | 4 | 3 |
254         When loading osm data
255             """
256             n1
257             n2
258             n3
259             n4
260             w1 Nn1,n2,n3,n4,n1
261             r1 Ttype=multipolygon,amenity=school Mw1@
262             r2 Ttype=site,amenity=school Mw1@
263             """
264         Then place contains exactly
265             | object     | type   |
266             | R1:amenity | school |
267             | R2:amenity | school |
268
269     Scenario: Exclude country relations
270         Given the lua style file
271             """
272             local flex = require('import-full')
273
274             function osm2pgsql.process_relation(object)
275                 if object.tags.boundary ~= 'administrative' or object.tags.admin_level ~= '2' then
276                   flex.process_relation(object)
277                 end
278             end
279             """
280        And the grid
281             | 1 | 2 |
282             | 4 | 3 |
283        When loading osm data
284             """
285             n1
286             n2
287             n3
288             n4
289             w1 Nn1,n2,n3,n4,n1
290             r1 Ttype=multipolygon,boundary=administrative,admin_level=4,name=Small Mw1@
291             r2 Ttype=multipolygon,boundary=administrative,admin_level=2,name=Big Mw1@
292             """
293         Then place contains exactly
294             | object      | type           |
295             | R1:boundary | administrative |
296
297     Scenario: Customize processing functions
298         Given the lua style file
299             """
300             local flex = require('import-full')
301
302             local original_process_tags = flex.process_tags
303
304             function flex.process_tags(o)
305                 if o.object.tags.highway ~= nil and o.object.tags.access == 'no' then
306                     return
307                 end
308
309                 original_process_tags(o)
310             end
311             """
312         When loading osm data
313             """
314             n1 Thighway=residential x0 y0
315             n2 Thighway=residential,access=no x0 y0
316             """
317         Then place contains exactly
318             | object     | type        |
319             | N1:highway | residential |