X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/d1b7c14f7987a20c218c96fe8071427536f8b36e..0cf636a80ce668e5c2a0d0000208f63a33315071:/lib-lua/themes/nominatim/init.lua diff --git a/lib-lua/themes/nominatim/init.lua b/lib-lua/themes/nominatim/init.lua index f8706bb9..fef86f91 100644 --- a/lib-lua/themes/nominatim/init.lua +++ b/lib-lua/themes/nominatim/init.lua @@ -40,12 +40,6 @@ if type(themepark) ~= 'table' then themepark = nil end --- tables required for taginfo -module.TAGINFO_MAIN = {keys = {}, delete_tags = {}} -module.TAGINFO_NAME_KEYS = {} -module.TAGINFO_ADDRESS_KEYS = {} - - -- The single place table. local place_table_definition = { name = "place", @@ -65,6 +59,8 @@ local place_table_definition = { } 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) @@ -138,6 +134,22 @@ function PlaceTransform.named_with_key(place, k) end end +-- Special transform used with address fallbacks: ignore all names +-- except for those marked as being part of the address. +local function address_fallback(place) + if next(place.names) == nil or NAMES.house == nil then + return place + end + + local names = {} + for k, v in pairs(place.names) do + if NAME_FILTER(k, v) == 'house' then + names[k] = v + end + end + return place:clone{names=names} +end + --------- Built-in extratags transformation functions --------------- local function default_extratags_filter(p, k) @@ -383,7 +395,7 @@ function Place:grab_name_parts(data) self.has_name = true elseif atype == 'house' then self.has_name = true - fallback = {'place', 'house', PlaceTransform.always} + fallback = {'place', 'house', address_fallback} end end end @@ -413,7 +425,7 @@ function Place:write_row(k, v) if self.geometry == nil then self.geometry = self.geom_func(self.object) end - if self.geometry:is_null() then + if self.geometry == nil or self.geometry:is_null() then return 0 end @@ -596,6 +608,9 @@ function module.process_way(object) if geom:is_null() then geom = o:as_linestring() + if geom:is_null() or geom:length() > 30 then + return nil + end end return geom @@ -640,7 +655,7 @@ function module.process_tags(o) -- address keys if o:grab_address_parts{groups=ADDRESS_FILTER} > 0 and fallback == nil then - fallback = {'place', 'house', PlaceTransform.always} + fallback = {'place', 'house', address_fallback} end if o.address.country ~= nil and #o.address.country ~= 2 then o.address['country'] = nil @@ -687,12 +702,26 @@ end 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) + 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 @@ -709,11 +738,25 @@ function module.set_main_tags(data) MAIN_KEYS[key] = nil end end - module.add_main_tags(data) + module.modify_main_tags(data) 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] = {} @@ -736,6 +779,14 @@ end 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 @@ -764,6 +815,14 @@ end 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 @@ -858,4 +917,9 @@ function module.set_relation_types(data) end end + +function module.get_taginfo() + return {main = MAIN_KEYS, name = NAMES, address = ADDRESS_TAGS} +end + return module