]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/features/osm2pgsql/import/custom_style.feature
release 5.3.2.post9
[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   | categories                               |
82             | N2     | amenity | -                | osm.amenity.hospital                     |
83             | N3     | tourism | 'amenity': 'yes' | osm.tourism.hotel                        |
84             | N4     | amenity | -                | osm.tourism.hotel, osm.amenity.telephone |
85
86     Scenario: Ignore some tags
87         Given the lua style file
88             """
89             local flex = require('import-extratags')
90
91             flex.ignore_keys{'ref:*', 'surface'}
92             """
93         When loading osm data
94             """
95             n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
96             """
97         Then place contains exactly
98             | object | name!dict    | extratags!dict |
99             | N100   | 'ref' : '34' | 'extra': '1'   |
100
101
102     Scenario: Add for extratags
103         Given the lua style file
104             """
105             local flex = require('import-full')
106
107             flex.add_for_extratags{'ref:*', 'surface'}
108             """
109         When loading osm data
110             """
111             n100 Thighway=residential,ref=34,ref:bodo=34,surface=gray,extra=1 x0 y0
112             """
113         Then place contains exactly
114             | object | name!dict    | extratags!dict  |
115             | N100   | 'ref' : '34' | 'ref:bodo': '34', 'surface': 'gray' |
116
117
118     Scenario: Name tags
119         Given the lua style file
120             """
121             local flex = require('flex-base')
122
123             flex.set_main_tags{highway = {traffic_light = 'named'}}
124             flex.set_name_tags{main = {'name', 'name:*'},
125                                extra = {'ref'}
126                               }
127             """
128         When loading osm data
129             """
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
134             """
135         Then place contains exactly
136             | object | class   | name!dict                  |
137             | N3     | highway | 'name': 'Greens'           |
138             | N4     | highway | 'name': 'Red', 'ref': '45' |
139
140     Scenario: Modify name tags
141         Given the lua style file
142             """
143             local flex = require('import-full')
144
145             flex.modify_name_tags{house = {}, extra = {'o'}}
146             """
147         When loading osm data
148             """
149             n1 Ttourism=hotel,ref=45,o=good
150             n2 Taddr:housename=Old,addr:street=Away
151             """
152         Then place contains exactly
153             | object | class   | name!dict   |
154             | N1     | tourism | 'o': 'good' |
155
156     Scenario: Address tags
157         Given the lua style file
158             """
159             local flex = require('import-full')
160
161             flex.set_address_tags{
162                 main = {'addr:housenumber'},
163                 extra = {'addr:*'},
164                 postcode = {'postal_code', 'postcode', 'addr:postcode'},
165                 country = {'country-code', 'ISO3166-1'}
166             }
167             """
168         When loading osm data
169             """
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
173             """
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' |
178
179     Scenario: Modify address tags
180         Given the lua style file
181             """
182             local flex = require('import-full')
183
184             flex.set_address_tags{
185                 extra = {'addr:*'},
186             }
187             """
188         When loading osm data
189             """
190             n2 Taddr:housenumber=23,addr:street=Budd,is_in:city=Faraway,postal_code=5567 x0 y0
191             """
192         Then place contains exactly
193             | object | class | type  | address!dict |
194             | N2     | place | house | 'housenumber': '23', 'street': 'Budd', 'postcode': '5567' |
195
196     Scenario: Unused handling (delete)
197         Given the lua style file
198             """
199             local flex = require('import-full')
200
201             flex.set_address_tags{
202                 main = {'addr:housenumber'},
203                 extra = {'addr:*', 'tiger:county'}
204             }
205             flex.set_unused_handling{delete_keys = {'tiger:*'}}
206             """
207         When loading osm data
208             """
209             n1 Ttourism=hotel,tiger:county=Fargo x0 y0
210             n2 Ttourism=hotel,tiger:xxd=56,else=other x0 y0
211             """
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'  |
216
217     Scenario: Unused handling (extra)
218         Given the lua style file
219             """
220             local flex = require('flex-base')
221             flex.set_main_tags{highway = 'always',
222                                wikipedia = 'extra'}
223             flex.add_for_extratags{'wikipedia:*', 'wikidata'}
224             flex.set_unused_handling{extra_keys = {'surface'}}
225             """
226         When loading osm data
227             """
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
233             """
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' |
241
242     Scenario: Additional relation types
243         Given the lua style file
244             """
245             local flex = require('import-full')
246
247             flex.RELATION_TYPES['site'] = flex.relation_as_multipolygon
248             """
249         And the grid
250             | 1 | 2 |
251             | 4 | 3 |
252         When loading osm data
253             """
254             n1
255             n2
256             n3
257             n4
258             w1 Nn1,n2,n3,n4,n1
259             r1 Ttype=multipolygon,amenity=school Mw1@
260             r2 Ttype=site,amenity=school Mw1@
261             """
262         Then place contains exactly
263             | object | class   | type   |
264             | R1     | amenity | school |
265             | R2     | amenity | school |
266
267     Scenario: Exclude country relations
268         Given the lua style file
269             """
270             local flex = require('import-full')
271
272             function osm2pgsql.process_relation(object)
273                 if object.tags.boundary ~= 'administrative' or object.tags.admin_level ~= '2' then
274                   flex.process_relation(object)
275                 end
276             end
277             """
278        And the grid
279             | 1 | 2 |
280             | 4 | 3 |
281        When loading osm data
282             """
283             n1
284             n2
285             n3
286             n4
287             w1 Nn1,n2,n3,n4,n1
288             r1 Ttype=multipolygon,boundary=administrative,admin_level=4,name=Small Mw1@
289             r2 Ttype=multipolygon,boundary=administrative,admin_level=2,name=Big Mw1@
290             """
291         Then place contains exactly
292             | object | class    | type           |
293             | R1     | boundary | administrative |
294
295     Scenario: Customize processing functions
296         Given the lua style file
297             """
298             local flex = require('import-full')
299
300             local original_process_tags = flex.process_tags
301
302             function flex.process_tags(o)
303                 if o.object.tags.highway ~= nil and o.object.tags.access == 'no' then
304                     return
305                 end
306
307                 original_process_tags(o)
308             end
309             """
310         When loading osm data
311             """
312             n1 Thighway=residential x0 y0
313             n2 Thighway=residential,access=no x0 y0
314             """
315         Then place contains exactly
316             | object | class   | type        |
317             | N1     | highway | residential |