]> git.openstreetmap.org Git - nominatim.git/commitdiff
convert import styles to themepark
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 6 Dec 2024 11:12:27 +0000 (12:12 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 16 Dec 2024 09:26:55 +0000 (10:26 +0100)
Introduces presets which avoid much of the previous configuration
duplication. The original import files are now thin wrappers around
the themepark themes.

15 files changed:
lib-lua/flex-base.lua
lib-lua/import-address.lua
lib-lua/import-admin.lua
lib-lua/import-extratags.lua
lib-lua/import-full.lua
lib-lua/import-street.lua
lib-lua/themes/nominatim/init.lua
lib-lua/themes/nominatim/presets.lua [new file with mode: 0644]
lib-lua/themes/nominatim/topics/address.lua [new file with mode: 0644]
lib-lua/themes/nominatim/topics/admin.lua [new file with mode: 0644]
lib-lua/themes/nominatim/topics/full.lua [new file with mode: 0644]
lib-lua/themes/nominatim/topics/street.lua [new file with mode: 0644]
test/bdd/api/details/simple.feature
test/bdd/osm2pgsql/import/custom_style.feature
test/bdd/osm2pgsql/import/tags.feature

index 9f9fda86459ab32fb78dcd98ab4743a12c2c2cfe..1173c53ff272ad018448daeab432b6b3f67a8efb 100644 (file)
@@ -4,6 +4,10 @@ local flex = require('themes/nominatim/init')
 function flex.load_topic(name, cfg)
     local topic_file = debug.getinfo(1, "S").source:sub(2):match("(.*/)") .. 'themes/nominatim/topics/'.. name .. '.lua'
 
 function flex.load_topic(name, cfg)
     local topic_file = debug.getinfo(1, "S").source:sub(2):match("(.*/)") .. 'themes/nominatim/topics/'.. name .. '.lua'
 
+    if topic_file == nil then
+        error('Cannot find topic: ' .. name)
+    end
+
     loadfile(topic_file)(nil, flex, cfg or {})
 end
 
     loadfile(topic_file)(nil, flex, cfg or {})
 end
 
index b177b73ca234994bbd1bc51dcf9b1a7ddb4a6b2e..bec21505a4b80b3a0ec88c3c12410ea468efd095 100644 (file)
@@ -1,74 +1,6 @@
+-- This is just an alias for the Nominatim themepark address topic
 local flex = require('flex-base')
 
 local flex = require('flex-base')
 
-flex.set_main_tags{
-    highway = {motorway = 'always',
-               trunk = 'always',
-               primary = 'always',
-               secondary = 'always',
-               tertiary = 'always',
-               unclassified = 'always',
-               residential = 'always',
-               road = 'always',
-               living_street = 'always',
-               pedestrian = 'always',
-               service = 'named',
-               cycleway = 'named',
-               path = 'named',
-               footway = 'named',
-               steps = 'named',
-               bridleway = 'named',
-               track = 'named',
-               motorway_link = 'named',
-               trunk_link = 'named',
-               primary_link = 'named',
-               secondary_link = 'named',
-               tertiary_link = 'named'},
-    boundary = {administrative = 'named',
-                postal_code = 'always'},
-    landuse = 'fallback',
-    place = 'always'
-}
-
-flex.set_prefilters{delete_keys = {'building', 'source',
-                                   'source', '*source', 'type',
-                                   'is_in:postcode', '*:wikidata', '*:wikipedia',
-                                   '*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
-                                   'name:etymology', 'name:signed', 'name:botanical',
-                                   'addr:street:name', 'addr:street:type'},
-                    delete_tags = {landuse = {'cemetry', 'no'},
-                                   boundary = {'place'}},
-                    extra_keys = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital', 'area'}
-                   }
-
-flex.set_name_tags{main = {'name', 'name:*',
-                          'int_name', 'int_name:*',
-                          'nat_name', 'nat_name:*',
-                          'reg_name', 'reg_name:*',
-                          'loc_name', 'loc_name:*',
-                          'old_name', 'old_name:*',
-                          'alt_name', 'alt_name:*', 'alt_name_*',
-                          'official_name', 'official_name:*',
-                          'place_name', 'place_name:*',
-                          'short_name', 'short_name:*'},
-                   extra = {'ref', 'int_ref', 'nat_ref', 'reg_ref',
-                            'loc_ref', 'old_ref',
-                            'iata', 'icao', 'pcode', 'pcode:*', 'ISO3166-2'},
-                   house = {'addr:housename'}
-                  }
-
-flex.set_address_tags{main = {'addr:housenumber',
-                              'addr:conscriptionnumber',
-                              'addr:streetnumber'},
-                      extra = {'addr:*', 'is_in:*', 'tiger:county'},
-                      postcode = {'postal_code', 'postcode', 'addr:postcode',
-                                  'tiger:zip_left', 'tiger:zip_right'},
-                      country = {'country_code', 'ISO3166-1',
-                                 'addr:country_code', 'is_in:country_code',
-                                 'addr:country', 'is_in:country'},
-                      interpolation = {'addr:interpolation'}
-                     }
-
-
-flex.set_unused_handling{extra_keys = {'place'}}
+flex.load_topic('address')
 
 return flex
 
 return flex
index 78eac5f5221d77ed69d9234f8593ffc4ae7ec952..8d1230a113f5913c916c2ef2a4c42e8033b0793c 100644 (file)
@@ -1,72 +1,6 @@
+-- This is just an alias for the Nominatim themepark admin topic
 local flex = require('flex-base')
 
 local flex = require('flex-base')
 
-flex.set_main_tags{
-    boundary = {administrative = 'named'},
-    landuse = {residential = 'fallback',
-               farm = 'fallback',
-               farmyard = 'fallback',
-               industrial = 'fallback',
-               commercial = 'fallback',
-               allotments = 'fallback',
-               retail = 'fallback'},
-    place = {county = 'always',
-             district = 'always',
-             municipality = 'always',
-             city = 'always',
-             town = 'always',
-             borough = 'always',
-             village = 'always',
-             suburb = 'always',
-             hamlet = 'always',
-             croft = 'always',
-             subdivision = 'always',
-             allotments = 'always',
-             neighbourhood = 'always',
-             quarter = 'always',
-             isolated_dwelling = 'always',
-             farm = 'always',
-             city_block = 'always',
-             mountain_pass = 'always',
-             square = 'always',
-             locality = 'always'}
-}
-
-flex.set_prefilters{delete_keys = {'building', 'source', 'highway',
-                                   'addr:housenumber', 'addr:street', 'addr:city',
-                                   'addr:interpolation',
-                                   'source', '*source', 'type',
-                                   'is_in:postcode', '*:wikidata', '*:wikipedia',
-                                   '*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
-                                   'name:etymology', 'name:signed', 'name:botanical',
-                                   'addr:street:name', 'addr:street:type'},
-                    delete_tags = {landuse = {'cemetry', 'no'},
-                                   boundary = {'place'}},
-                    extra_keys = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital'}
-                   }
-
-flex.set_name_tags{main = {'name', 'name:*',
-                          'int_name', 'int_name:*',
-                          'nat_name', 'nat_name:*',
-                          'reg_name', 'reg_name:*',
-                          'loc_name', 'loc_name:*',
-                          'old_name', 'old_name:*',
-                          'alt_name', 'alt_name:*', 'alt_name_*',
-                          'official_name', 'official_name:*',
-                          'place_name', 'place_name:*',
-                          'short_name', 'short_name:*'},
-                   extra = {'ref', 'int_ref', 'nat_ref', 'reg_ref',
-                            'loc_ref', 'old_ref',
-                            'iata', 'icao', 'pcode', 'pcode:*', 'ISO3166-2'}
-                  }
-
-flex.set_address_tags{extra = {'addr:*', 'is_in:*'},
-                      postcode = {'postal_code', 'postcode', 'addr:postcode'},
-                      country = {'country_code', 'ISO3166-1',
-                                 'addr:country_code', 'is_in:country_code',
-                                 'addr:country', 'is_in:country'},
-                      postcode_fallback = false
-                     }
-
-flex.set_unused_handling{extra_keys = {'place'}}
+flex.load_topic('admin')
 
 return flex
 
 return flex
index 0d242b0f30409f34ac3b5382066e4ef77412c108..53b1c81e6f9e2085c65165c216313c9932b94cf5 100644 (file)
@@ -1,126 +1,6 @@
+-- This is just an alias for the Nominatim themepark full topic
 local flex = require('flex-base')
 
 local flex = require('flex-base')
 
-flex.set_main_tags{
-    building = 'fallback',
-    emergency = 'always',
-    healthcare = 'fallback',
-    historic = 'always',
-    military = 'always',
-    natural = 'named',
-    highway = {'always',
-               street_lamp = 'named',
-               traffic_signals = 'named',
-               service = 'named',
-               cycleway = 'named',
-               path = 'named',
-               footway = 'named',
-               steps = 'named',
-               bridleway = 'named',
-               track = 'named',
-               motorway_link = 'named',
-               trunk_link = 'named',
-               primary_link = 'named',
-               secondary_link = 'named',
-               tertiary_link = 'named'},
-    railway = 'named',
-    man_made = {'none',
-                pier = 'always',
-                tower = 'always',
-                bridge = 'always',
-                works = 'named',
-                water_tower = 'always',
-                dyke = 'named',
-                adit = 'named',
-                lighthouse = 'always',
-                watermill = 'always',
-                tunnel = 'always'},
-    aerialway = 'always',
-    boundary = {'named',
-                postal_code = 'always'},
-    aeroway = 'always',
-    amenity = 'always',
-    club = 'always',
-    craft = 'always',
-    junction = 'fallback',
-    landuse = 'fallback',
-    leisure = {'always',
-               nature_reserve = 'fallback'},
-    office = 'always',
-    mountain_pass = 'always',
-    shop = 'always',
-    tourism = 'always',
-    bridge = 'named_with_key',
-    tunnel = 'named_with_key',
-    waterway = 'named',
-    place = 'always'
-}
-
-flex.set_prefilters{delete_keys = {'note', 'note:*', 'source', '*source', 'attribution',
-                                   'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*',
-                                   'nhd:*', 'gnis:*', 'geobase:*', 'KSJ2:*', 'yh:*',
-                                   'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*',
-                                   'type', 'lacounty:*', 'ref:ruian:*', 'building:ruian:type',
-                                   'ref:linz:*', 'is_in:postcode'},
-                    delete_tags = {emergency = {'yes', 'no', 'fire_hydrant'},
-                                   historic = {'yes', 'no'},
-                                   military = {'yes', 'no'},
-                                   natural = {'yes', 'no', 'coastline'},
-                                   highway = {'no', 'turning_circle', 'mini_roundabout',
-                                              'noexit', 'crossing', 'give_way', 'stop'},
-                                   railway = {'level_crossing', 'no', 'rail', 'switch',
-                                              'abandoned', 'signal', 'buffer_stop', 'razed'},
-                                   aerialway = {'pylon', 'no'},
-                                   aeroway = {'no'},
-                                   amenity = {'no', 'parking_space', 'parking_entrance',
-                                              'waste_disposal', 'hunting_stand'},
-                                   club = {'no'},
-                                   craft = {'no'},
-                                   leisure = {'no'},
-                                   office = {'no'},
-                                   mountain_pass = {'no'},
-                                   shop = {'no'},
-                                   tourism = {'yes', 'no'},
-                                   bridge = {'no'},
-                                   tunnel = {'no'},
-                                   waterway = {'riverbank'},
-                                   building = {'no'},
-                                   boundary = {'place', 'land_area'}},
-                    extra_keys = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
-                               'name:etymology', 'name:signed', 'name:botanical',
-                               'wikidata', '*:wikidata',
-                               '*:wikipedia', 'brand:wikipedia:*',
-                               'addr:street:name', 'addr:street:type'}
-                   }
-
-flex.set_name_tags{main = {'name', 'name:*',
-                          'int_name', 'int_name:*',
-                          'nat_name', 'nat_name:*',
-                          'reg_name', 'reg_name:*',
-                          'loc_name', 'loc_name:*',
-                          'old_name', 'old_name:*',
-                          'alt_name', 'alt_name:*', 'alt_name_*',
-                          'official_name', 'official_name:*',
-                          'place_name', 'place_name:*',
-                          'short_name', 'short_name:*', 'brand'},
-                   extra = {'ref', 'int_ref', 'nat_ref', 'reg_ref',
-                            'loc_ref', 'old_ref',
-                            'iata', 'icao', 'pcode', 'pcode:*', 'ISO3166-2'},
-                   house = {'addr:housename'}
-                  }
-
-flex.set_address_tags{main = {'addr:housenumber',
-                              'addr:conscriptionnumber',
-                              'addr:streetnumber'},
-                      extra = {'addr:*', 'is_in:*', 'tiger:county'},
-                      postcode = {'postal_code', 'postcode', 'addr:postcode',
-                                  'tiger:zip_left', 'tiger:zip_right'},
-                      country = {'country_code', 'ISO3166-1',
-                                 'addr:country_code', 'is_in:country_code',
-                                 'addr:country', 'is_in:country'},
-                      interpolation = {'addr:interpolation'}
-                     }
-
-
-flex.set_unused_handling{delete_keys = {'tiger:*'}}
+flex.load_topic('full', {with_extratags = true})
 
 return flex
 
 return flex
index 11bd1f3a7f98a524eac06884e8b8e96c66a41a93..59308a672bcce540ec08c865eceb47060f38e9b0 100644 (file)
@@ -1,126 +1,6 @@
+-- This is just an alias for the Nominatim themepark full topic
 local flex = require('flex-base')
 
 local flex = require('flex-base')
 
-flex.set_main_tags{
-    building = 'fallback',
-    emergency = 'always',
-    healthcare = 'fallback',
-    historic = 'always',
-    military = 'always',
-    natural = 'named',
-    highway = {'always',
-               street_lamp = 'named',
-               traffic_signals = 'named',
-               service = 'named',
-               cycleway = 'named',
-               path = 'named',
-               footway = 'named',
-               steps = 'named',
-               bridleway = 'named',
-               track = 'named',
-               motorway_link = 'named',
-               trunk_link = 'named',
-               primary_link = 'named',
-               secondary_link = 'named',
-               tertiary_link = 'named'},
-    railway = 'named',
-    man_made = {'none',
-                pier = 'always',
-                tower = 'always',
-                bridge = 'always',
-                works = 'named',
-                water_tower = 'always',
-                dyke = 'named',
-                adit = 'named',
-                lighthouse = 'always',
-                watermill = 'always',
-                tunnel = 'always'},
-    aerialway = 'always',
-    boundary = {'named',
-                postal_code = 'always'},
-    aeroway = 'always',
-    amenity = 'always',
-    club = 'always',
-    craft = 'always',
-    junction = 'fallback',
-    landuse = 'fallback',
-    leisure = {'always',
-               nature_reserve = 'fallback'},
-    office = 'always',
-    mountain_pass = 'always',
-    shop = 'always',
-    tourism = 'always',
-    bridge = 'named_with_key',
-    tunnel = 'named_with_key',
-    waterway = 'named',
-    place = 'always'
-}
-
-flex.set_prefilters{delete_keys = {'note', 'note:*', 'source', '*source', 'attribution',
-                                   'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*',
-                                   'nhd:*', 'gnis:*', 'geobase:*', 'KSJ2:*', 'yh:*',
-                                   'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*',
-                                   'type', 'lacounty:*', 'ref:ruian:*', 'building:ruian:type',
-                                   'ref:linz:*', 'is_in:postcode',
-                                   '*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
-                                   'name:etymology', 'name:signed', 'name:botanical',
-                                   '*:wikidata', '*:wikipedia', 'brand:wikipedia:*',
-                                   'addr:street:name', 'addr:street:type'},
-                    delete_tags = {emergency = {'yes', 'no', 'fire_hydrant'},
-                                   historic = {'yes', 'no'},
-                                   military = {'yes', 'no'},
-                                   natural = {'yes', 'no', 'coastline'},
-                                   highway = {'no', 'turning_circle', 'mini_roundabout',
-                                              'noexit', 'crossing', 'give_way', 'stop'},
-                                   railway = {'level_crossing', 'no', 'rail', 'switch',
-                                              'abandoned', 'signal', 'buffer_stop', 'razed'},
-                                   aerialway = {'pylon', 'no'},
-                                   aeroway = {'no'},
-                                   amenity = {'no', 'parking_space', 'parking_entrance',
-                                              'waste_disposal', 'hunting_stand'},
-                                   club = {'no'},
-                                   craft = {'no'},
-                                   leisure = {'no'},
-                                   office = {'no'},
-                                   mountain_pass = {'no'},
-                                   shop = {'no'},
-                                   tourism = {'yes', 'no'},
-                                   bridge = {'no'},
-                                   tunnel = {'no'},
-                                   waterway = {'riverbank'},
-                                   building = {'no'},
-                                   boundary = {'place', 'land_area'}},
-                    extra_keys = {'wikidata', 'wikipedia', 'wikipedia:*'}
-                   }
-
-flex.set_name_tags{main = {'name', 'name:*',
-                          'int_name', 'int_name:*',
-                          'nat_name', 'nat_name:*',
-                          'reg_name', 'reg_name:*',
-                          'loc_name', 'loc_name:*',
-                          'old_name', 'old_name:*',
-                          'alt_name', 'alt_name:*', 'alt_name_*',
-                          'official_name', 'official_name:*',
-                          'place_name', 'place_name:*',
-                          'short_name', 'short_name:*', 'brand'},
-                   extra = {'ref', 'int_ref', 'nat_ref', 'reg_ref',
-                            'loc_ref', 'old_ref',
-                            'iata', 'icao', 'pcode', 'pcode:*', 'ISO3166-2'},
-                   house = {'addr:housename'}
-                  }
-
-flex.set_address_tags{main = {'addr:housenumber',
-                              'addr:conscriptionnumber',
-                              'addr:streetnumber'},
-                      extra = {'addr:*', 'is_in:*', 'tiger:county'},
-                      postcode = {'postal_code', 'postcode', 'addr:postcode',
-                                  'tiger:zip_left', 'tiger:zip_right'},
-                      country = {'country_code', 'ISO3166-1',
-                                 'addr:country_code', 'is_in:country_code',
-                                 'addr:country', 'is_in:country'},
-                      interpolation = {'addr:interpolation'}
-                     }
-
-
-flex.set_unused_handling{extra_keys = {'place'}}
+flex.load_topic('full')
 
 return flex
 
 return flex
index 60b76dfb3d1fa296e94f455555105e6aa302697e..1a02b09859f3a850ae45ef8ed7c644cc062213b0 100644 (file)
@@ -1,74 +1,6 @@
+-- This is just an alias for the Nominatim themepark street topic
 local flex = require('flex-base')
 
 local flex = require('flex-base')
 
-flex.set_main_tags{
-    highway = {motorway = 'always',
-               trunk = 'always',
-               primary = 'always',
-               secondary = 'always',
-               tertiary = 'always',
-               unclassified = 'always',
-               residential = 'always',
-               road = 'always',
-               living_street = 'always',
-               pedestrian = 'always',
-               service = 'named',
-               cycleway = 'named',
-               path = 'named',
-               footway = 'named',
-               steps = 'named',
-               bridleway = 'named',
-               track = 'named',
-               motorway_link = 'named',
-               trunk_link = 'named',
-               primary_link = 'named',
-               secondary_link = 'named',
-               tertiary_link = 'named'},
-    boundary = {administrative = 'named',
-                postal_code = 'always'},
-    landuse = 'fallback',
-    place = 'always'
-}
-
-flex.set_prefilters{delete_keys = {'building', 'source',
-                                   'addr:housenumber', 'addr:street',
-                                   'source', '*source', 'type',
-                                   'is_in:postcode', '*:wikidata', '*:wikipedia',
-                                   '*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
-                                   'name:etymology', 'name:signed', 'name:botanical',
-                                   'addr:street:name', 'addr:street:type'},
-                    delete_tags = {landuse = {'cemetry', 'no'},
-                                   boundary = {'place'}},
-                    extra_keys = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital', 'area'}
-                   }
-
-flex.set_name_tags{main = {'name', 'name:*',
-                          'int_name', 'int_name:*',
-                          'nat_name', 'nat_name:*',
-                          'reg_name', 'reg_name:*',
-                          'loc_name', 'loc_name:*',
-                          'old_name', 'old_name:*',
-                          'alt_name', 'alt_name:*', 'alt_name_*',
-                          'official_name', 'official_name:*',
-                          'place_name', 'place_name:*',
-                          'short_name', 'short_name:*'},
-                   extra = {'ref', 'int_ref', 'nat_ref', 'reg_ref',
-                            'loc_ref', 'old_ref',
-                            'iata', 'icao', 'pcode', 'pcode:*', 'ISO3166-2'}
-                  }
-
-flex.set_address_tags{main = {'addr:housenumber',
-                              'addr:conscriptionnumber',
-                              'addr:streetnumber'},
-                      extra = {'addr:*', 'is_in:*', 'tiger:county'},
-                      postcode = {'postal_code', 'postcode', 'addr:postcode',
-                                  'tiger:zip_left', 'tiger:zip_right'},
-                      country = {'country_code', 'ISO3166-1',
-                                 'addr:country_code', 'is_in:country_code',
-                                 'addr:country', 'is_in:country'},
-                      interpolation = {'addr:interpolation'},
-                      postcode_fallback = false
-                     }
-
-flex.set_unused_handling{extra_keys = {'place'}}
+flex.load_topic('street')
 
 return flex
 
 return flex
index f8706bb92b6c285809091902df85fe8174c50eb6..8f88f0c1a6761222aa23202bc1a75e5f9865f861 100644 (file)
@@ -65,6 +65,8 @@ local place_table_definition = {
 }
 
 local insert_row
 }
 
 local insert_row
+local script_path = debug.getinfo(1, "S").source:match("@?(.*/)")
+local PRESETS = loadfile(script_path .. 'presets.lua')()
 
 if themepark then
     themepark:add_table(place_table_definition)
 
 if themepark then
     themepark:add_table(place_table_definition)
@@ -687,12 +689,26 @@ end
 
 
 function module.ignore_keys(data)
 
 
 function module.ignore_keys(data)
+    if type(data) == 'string' then
+        local preset = data
+        data = PRESETS.IGNORE_KEYS[data]
+        if data == nil then
+            error('Unknown preset for ignored keys: ' .. preset)
+        end
+    end
     merge_filters_into_main('delete', data)
     add_pre_filter{delete = data}
 end
 
 
 function module.add_for_extratags(data)
     merge_filters_into_main('delete', data)
     add_pre_filter{delete = data}
 end
 
 
 function module.add_for_extratags(data)
+    if type(data) == 'string' then
+        local preset = data
+        data = PRESETS.EXTRATAGS[data] or PRESETS.IGNORE_KEYS[data]
+        if data == nil then
+            error('Unknown preset for extratags: ' .. preset)
+        end
+    end
     merge_filters_into_main('extra', data)
     add_pre_filter{extra = data}
 end
     merge_filters_into_main('extra', data)
     add_pre_filter{extra = data}
 end
@@ -709,11 +725,25 @@ function module.set_main_tags(data)
             MAIN_KEYS[key] = nil
         end
     end
             MAIN_KEYS[key] = nil
         end
     end
-    module.add_main_tags(data)
+    module.modify_main_tags(data)
 end
 
 
 end
 
 
-function module.add_main_tags(data)
+function module.modify_main_tags(data)
+    if type(data) == 'string' then
+        local preset = data
+        if data:sub(1, 7) == 'street/' then
+            data = PRESETS.MAIN_TAGS_STREETS[data:sub(8)]
+        elseif data:sub(1, 4) == 'poi/' then
+            data = PRESETS.MAIN_TAGS_POIS(data:sub(5))
+        else
+            data = PRESETS.MAIN_TAGS[data]
+        end
+        if data == nil then
+            error('Unknown preset for main tags: ' .. preset)
+        end
+    end
+
     for k, v in pairs(data) do
         if MAIN_KEYS[k] == nil then
             MAIN_KEYS[k] = {}
     for k, v in pairs(data) do
         if MAIN_KEYS[k] == nil then
             MAIN_KEYS[k] = {}
@@ -736,6 +766,14 @@ end
 
 
 function module.modify_name_tags(data)
 
 
 function module.modify_name_tags(data)
+    if type(data) == 'string' then
+        local preset = data
+        data = PRESETS.NAME_TAGS[data]
+        if data == nil then
+            error('Unknown preset for name keys: ' .. preset)
+        end
+    end
+
     for k,v in pairs(data) do
         if next(v) then
             NAMES[k] = v
     for k,v in pairs(data) do
         if next(v) then
             NAMES[k] = v
@@ -764,6 +802,14 @@ end
 
 
 function module.modify_address_tags(data)
 
 
 function module.modify_address_tags(data)
+    if type(data) == 'string' then
+        local preset = data
+        data = PRESETS.ADDRESS_TAGS[data]
+        if data == nil then
+            error('Unknown preset for address keys: ' .. preset)
+        end
+    end
+
     for k, v in pairs(data) do
         if k == 'postcode_fallback' then
             POSTCODE_FALLBACK = v
     for k, v in pairs(data) do
         if k == 'postcode_fallback' then
             POSTCODE_FALLBACK = v
diff --git a/lib-lua/themes/nominatim/presets.lua b/lib-lua/themes/nominatim/presets.lua
new file mode 100644 (file)
index 0000000..0193281
--- /dev/null
@@ -0,0 +1,281 @@
+-- Defines defaults used in the topic definitions.
+
+local module = {}
+
+-- Main tag definition
+
+module.MAIN_TAGS = {}
+
+module.MAIN_TAGS.admin = {
+    boundary = {administrative = 'named'},
+    landuse = {residential = 'fallback',
+               farm = 'fallback',
+               farmyard = 'fallback',
+               industrial = 'fallback',
+               commercial = 'fallback',
+               allotments = 'fallback',
+               retail = 'fallback'},
+    place = {county = 'always',
+             district = 'always',
+             municipality = 'always',
+             city = 'always',
+             town = 'always',
+             borough = 'always',
+             village = 'always',
+             suburb = 'always',
+             hamlet = 'always',
+             croft = 'always',
+             subdivision = 'always',
+             allotments = 'always',
+             neighbourhood = 'always',
+             quarter = 'always',
+             isolated_dwelling = 'always',
+             farm = 'always',
+             city_block = 'always',
+             locality = 'always'}
+}
+
+module.MAIN_TAGS.all_boundaries = {
+    boundary = {'named',
+                place = 'delete',
+                land_area = 'delete',
+                postal_code = 'always'},
+    landuse = 'fallback',
+    place = 'always'
+}
+
+module.MAIN_TAGS.natural = {
+    waterway = {'named',
+                riverbank = 'delete'},
+    natural = {'named',
+               yes = 'delete',
+               no = 'delete',
+               coastline = 'delete',
+               saddle = 'fallback'},
+    mountain_pass = {'always',
+                     no = 'delete'}
+}
+
+module.MAIN_TAGS_POIS = function (group)
+    group = group or 'delete'
+    return {
+    aerialway = {'always',
+                 no = group,
+                 pylon = group},
+    aeroway = {'always',
+               no = group},
+    amenity = {'always',
+               no = group,
+               parking_space = group,
+               parking_entrance = group,
+               waste_disposal = group,
+               hunting_stand = group},
+    building = {'fallback',
+                no = group},
+    bridge = {'named_with_key',
+              no = group},
+    club = {'always',
+            no = group},
+    craft = {'always',
+             no = group},
+    emergency = {'always',
+                 no = group,
+                 yes = group,
+                 fire_hydrant = group},
+    healthcare = {'fallback',
+                  yes = group,
+                  no = group},
+    highway = {'always',
+               no = group,
+               turning_circle = group,
+               mini_roundabout = group,
+               noexit = group,
+               crossing = group,
+               give_way = group,
+               stop = group,
+               turning_loop = group,
+               passing_place = group,
+               street_lamp = 'named',
+               traffic_signals = 'named'},
+    historic = {'always',
+                yes = group,
+                no = group},
+    junction = {'fallback',
+                no = group},
+    leisure = {'always',
+               nature_reserve = 'fallback',
+               no = group},
+    man_made = {pier = 'always',
+                tower = 'always',
+                bridge = 'always',
+                works = 'named',
+                water_tower = 'always',
+                dyke = 'named',
+                adit = 'named',
+                lighthouse = 'always',
+                watermill = 'always',
+                tunnel = 'always'},
+    military = {'always',
+                yes = group,
+                no = group},
+    office = {'always',
+              no = group},
+    railway = {'named',
+               rail = group,
+               no = group,
+               abandoned = group,
+               disused = group,
+               razed = group,
+               level_crossing = group,
+               switch = group,
+               signal = group,
+               buffer_stop = group},
+    shop = {'always',
+            no = group},
+    tourism = {'always',
+               no = group,
+               yes = group},
+    tunnel = {'named_with_key',
+              no = group}
+} end
+
+module.MAIN_TAGS_STREETS = {}
+
+module.MAIN_TAGS_STREETS.default = {
+    place = {square = 'always'},
+    highway = {motorway = 'always',
+               trunk = 'always',
+               primary = 'always',
+               secondary = 'always',
+               tertiary = 'always',
+               unclassified = 'always',
+               residential = 'always',
+               road = 'always',
+               living_street = 'always',
+               pedestrian = 'always',
+               service = 'named',
+               cycleway = 'named',
+               path = 'named',
+               footway = 'named',
+               steps = 'named',
+               bridleway = 'named',
+               track = 'named',
+               motorway_link = 'named',
+               trunk_link = 'named',
+               primary_link = 'named',
+               secondary_link = 'named',
+               tertiary_link = 'named'}
+}
+
+module.MAIN_TAGS_STREETS.car = {
+    place = {square = 'always'},
+    highway = {motorway = 'always',
+               trunk = 'always',
+               primary = 'always',
+               secondary = 'always',
+               tertiary = 'always',
+               unclassified = 'always',
+               residential = 'always',
+               road = 'always',
+               living_street = 'always',
+               service = 'always',
+               track = 'always',
+               motorway_link = 'always',
+               trunk_link = 'always',
+               primary_link = 'always',
+               secondary_link = 'always',
+               tertiary_link = 'always'}
+}
+
+module.MAIN_TAGS_STREETS.all = {
+    place = {square = 'always'},
+    highway = {motorway = 'always',
+               trunk = 'always',
+               primary = 'always',
+               secondary = 'always',
+               tertiary = 'always',
+               unclassified = 'always',
+               residential = 'always',
+               road = 'always',
+               living_street = 'always',
+               pedestrian = 'always',
+               service = 'always',
+               cycleway = 'always',
+               path = 'always',
+               footway = 'always',
+               steps = 'always',
+               bridleway = 'always',
+               track = 'always',
+               motorway_link = 'always',
+               trunk_link = 'always',
+               primary_link = 'always',
+               secondary_link = 'always',
+               tertiary_link = 'always'}
+}
+
+
+-- name tags
+
+module.NAME_TAGS = {}
+
+module.NAME_TAGS.core = {main = {'name', 'name:*',
+                                 'int_name', 'int_name:*',
+                                 'nat_name', 'nat_name:*',
+                                 'reg_name', 'reg_name:*',
+                                 'loc_name', 'loc_name:*',
+                                 'old_name', 'old_name:*',
+                                 'alt_name', 'alt_name:*', 'alt_name_*',
+                                 'official_name', 'official_name:*',
+                                 'place_name', 'place_name:*',
+                                 'short_name', 'short_name:*'},
+                         extra = {'ref', 'int_ref', 'nat_ref', 'reg_ref',
+                                  'loc_ref', 'old_ref', 'ISO3166-2'}
+                        }
+module.NAME_TAGS.address = {house = {'addr:housename'}}
+module.NAME_TAGS.poi = {extra = {'ref', 'int_ref', 'nat_ref', 'reg_ref',
+                                       'loc_ref', 'old_ref',
+                                       'iata', 'icao',
+                                       'ISO3166-2'}}
+
+-- Address tagging
+
+module.ADDRESS_TAGS = {}
+
+module.ADDRESS_TAGS.core = { extra = {'addr:*', 'is_in:*', 'tiger:county'},
+                             postcode = {'postal_code', 'postcode', 'addr:postcode',
+                                         'tiger:zip_left', 'tiger:zip_right'},
+                             country = {'country_code', 'ISO3166-1',
+                                        'addr:country_code', 'is_in:country_code',
+                                        'addr:country', 'is_in:country'}
+                           }
+
+module.ADDRESS_TAGS.houses = { main = {'addr:housenumber',
+                                       'addr:conscriptionnumber',
+                                       'addr:streetnumber'},
+                               interpolation = {'addr:interpolation'}
+                             }
+
+-- Ignored tags (prefiltered away)
+
+module.IGNORE_KEYS = {}
+
+module.IGNORE_KEYS.metatags = {'note', 'note:*', 'source', 'source:*', '*source',
+                               'attribution', 'comment', 'fixme', 'created_by',
+                               'tiger:cfcc', 'tiger:reviewed', 'nysgissam:*',
+                               'NHD:*', 'nhd:*', 'gnis:*', 'geobase:*', 'yh:*',
+                               'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*',
+                               'lacounty:*', 'ref:linz:*',
+                               'ref:bygningsnr', 'ref:ruian:*', 'building:ruian:type',
+                               'type',
+                               'is_in:postcode'}
+module.IGNORE_KEYS.name = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
+                           'name:etymology', 'name:signed', 'name:botanical'}
+module.IGNORE_KEYS.address = {'addr:street:*', 'addr:TW:dataset'}
+
+-- Extra tags (prefiltered away)
+
+module.EXTRATAGS = {}
+
+module.EXTRATAGS.required = {'wikipedia', 'wikipedia:*', 'wikidata', 'capital'}
+
+return module
diff --git a/lib-lua/themes/nominatim/topics/address.lua b/lib-lua/themes/nominatim/topics/address.lua
new file mode 100644 (file)
index 0000000..0e81367
--- /dev/null
@@ -0,0 +1,23 @@
+local _, flex, cfg = ...
+
+flex.set_main_tags('admin')
+flex.modify_main_tags('street/' .. (cfg.street_theme or 'default'))
+flex.modify_main_tags{boundary = {postal_code = 'always'}}
+
+flex.set_name_tags('core')
+flex.modify_name_tags('address')
+
+flex.set_address_tags('core')
+flex.modify_address_tags('houses')
+
+flex.ignore_keys('metatags')
+flex.add_for_extratags('required')
+
+if cfg.with_extratags then
+    flex.set_unused_handling{delete_keys = {'tiger:*'}}
+    flex.add_for_extratags('name')
+    flex.add_for_extratags('address')
+else
+    flex.ignore_keys('name')
+    flex.ignore_keys('address')
+end
diff --git a/lib-lua/themes/nominatim/topics/admin.lua b/lib-lua/themes/nominatim/topics/admin.lua
new file mode 100644 (file)
index 0000000..47f4e24
--- /dev/null
@@ -0,0 +1,20 @@
+local _, flex, cfg = ...
+
+flex.set_main_tags('admin')
+
+flex.set_name_tags('core')
+
+flex.set_address_tags('core')
+flex.set_postcode_fallback(false)
+
+flex.ignore_keys('metatags')
+flex.add_for_extratags('required')
+
+if cfg.with_extratags then
+    flex.set_unused_handling{delete_keys = {'tiger:*'}}
+    flex.add_for_extratags('name')
+    flex.add_for_extratags('address')
+else
+    flex.ignore_keys('name')
+    flex.ignore_keys('address')
+end
diff --git a/lib-lua/themes/nominatim/topics/full.lua b/lib-lua/themes/nominatim/topics/full.lua
new file mode 100644 (file)
index 0000000..a0b61b0
--- /dev/null
@@ -0,0 +1,32 @@
+local _, flex, cfg = ...
+
+local group
+if cfg.with_extratags then
+    group = 'extra'
+else
+    group = 'delete'
+end
+
+flex.set_main_tags('all_boundaries')
+flex.modify_main_tags('natural')
+flex.modify_main_tags('street/' .. (cfg.street_theme or 'default'))
+flex.modify_main_tags('poi/' .. group)
+
+flex.set_name_tags('core')
+flex.modify_name_tags('address')
+flex.modify_name_tags('poi')
+
+flex.set_address_tags('core')
+flex.modify_address_tags('houses')
+
+flex.ignore_keys('metatags')
+flex.add_for_extratags('required')
+
+if cfg.with_extratags then
+    flex.set_unused_handling{delete_keys = {'tiger:*'}}
+    flex.add_for_extratags('name')
+    flex.add_for_extratags('address')
+else
+    flex.ignore_keys('name')
+    flex.ignore_keys('address')
+end
diff --git a/lib-lua/themes/nominatim/topics/street.lua b/lib-lua/themes/nominatim/topics/street.lua
new file mode 100644 (file)
index 0000000..89bed44
--- /dev/null
@@ -0,0 +1,22 @@
+local _, flex, cfg = ...
+
+flex.set_main_tags('admin')
+flex.modify_main_tags('street/' .. (cfg.street_theme or 'default'))
+flex.modify_main_tags{boundary = {postal_code = 'always'}}
+
+flex.set_name_tags('core')
+
+flex.set_address_tags('core')
+flex.set_postcode_fallback(false)
+
+flex.ignore_keys('metatags')
+flex.add_for_extratags('required')
+
+if cfg.with_extratags then
+    flex.set_unused_handling{delete_keys = {'tiger:*'}}
+    flex.add_for_extratags('name')
+    flex.add_for_extratags('address')
+else
+    flex.ignore_keys('name')
+    flex.ignore_keys('address')
+end
index 5e0bacc5a945b2909691072885b194e1fd032136..a3cc95e53b19e70678fae06d0fff175462379ccb 100644 (file)
@@ -27,7 +27,6 @@ Feature: Object details
     Examples:
      | class |
      | tourism |
     Examples:
      | class |
      | tourism |
-     | natural |
      | mountain_pass |
 
 
      | mountain_pass |
 
 
index 405afdb5c4dc8c2d0c363e43439d64338c7ff0fe..15852c5d3a028cb9834becdd3da4b8593ede9202 100644 (file)
@@ -33,7 +33,7 @@ Feature: Import with custom styles by osm2pgsql
             """
             local flex = require('import-full')
 
             """
             local flex = require('import-full')
 
-            flex.add_main_tags{
+            flex.modify_main_tags{
                 amenity = {prison = 'delete'},
                 highway = {stop = 'named'},
                 aeroway = 'named'
                 amenity = {prison = 'delete'},
                 highway = {stop = 'named'},
                 aeroway = 'named'
index 7958f4b35bd8efd0f49ea0e9492543cfbab21c66..cf530eb7d9ce5e81f685b6a03d369b3e789df55c 100644 (file)
@@ -131,7 +131,7 @@ Feature: Tag evaluation
         When loading osm data
             """
             n8001 Tshop=shoes,note:de=Nein,xx=yy
         When loading osm data
             """
             n8001 Tshop=shoes,note:de=Nein,xx=yy
-            n8002 Tshop=shoes,building=no,ele=234
+            n8002 Tshop=shoes,natural=no,ele=234
             n8003 Tshop=shoes,name:source=survey
             """
         Then place contains exactly
             n8003 Tshop=shoes,name:source=survey
             """
         Then place contains exactly