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