1 -- Nominatim themepark theme.
3 -- The Nominatim theme creates a fixed set of import tables for use with
4 -- Nominatim. Creation and object processing are directly controlled by
5 -- the theme. Topics provide preset configurations. You should add exactly
6 -- one topic to your project.
8 -- The theme also exports a number of functions that can be used to configure
9 -- its behaviour. These may be directly called in the style file after
10 -- importing the theme:
12 -- local nominatim = themepark:init_theme('nominatim')
13 -- nominatim.set_main_tags{boundary = 'always'}
15 -- This allows to write your own configuration from scratch. You can also
16 -- use it to customize topics. In that case, first add the topic, then
17 -- change the configuration:
19 -- themepark:add_topic('nominatim/full')
20 -- local nominatim = themepark:init_theme('nominatim')
21 -- nominatim.ignore_tags{'amenity'}
25 local MAIN_KEYS = {admin_level = {'delete'}}
26 local PRE_FILTER = {prefix = {}, suffix = {}}
28 local NAME_FILTER = nil
29 local ADDRESS_TAGS = {}
30 local ADDRESS_FILTER = nil
31 local EXTRATAGS_FILTER
32 local REQUIRED_EXTRATAGS_FILTER
33 local POSTCODE_FALLBACK = true
34 local ENTRANCE_FUNCTION = nil
36 -- This file can also be directly require'd instead of running it under
37 -- the themepark framework. In that case the first parameter is usually
38 -- the module name. Lets check for that, so that further down we can call
39 -- the low-level osm2pgsql functions instead of themepark functions.
41 if type(themepark) ~= 'table' then
45 -- The place tables carry the raw OSM information.
46 local table_definitions = {
48 ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
50 { column = 'class', type = 'text', not_null = true },
51 { column = 'type', type = 'text', not_null = true },
52 { column = 'admin_level', type = 'smallint' },
53 { column = 'name', type = 'hstore' },
54 { column = 'address', type = 'hstore' },
55 { column = 'extratags', type = 'hstore' },
56 { column = 'geometry', type = 'geometry', projection = 'WGS84', not_null = true },
57 { column = 'categories', sql_type = 'ltree[]' }
62 ids = { type = 'node', id_column = 'osm_id' },
64 { column = 'type', type = 'text', not_null = true },
65 { column = 'extratags', type = 'hstore' },
66 { column = 'geometry', type = 'geometry', projection = 'WGS84', not_null = true }
71 ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
73 { column = 'postcode', type = 'text', not_null = true },
74 { column = 'country_code', type = 'text' },
75 { column = 'centroid', type = 'point', projection = 'WGS84', not_null = true },
76 { column = 'geometry', type = 'geometry', projection = 'WGS84' }
79 { column = 'postcode', method = 'btree' }
82 place_interpolation = {
83 ids = { type = 'way', id_column = 'osm_id' },
85 { column = 'type', type = 'text', not_null = true },
86 { column = 'address', type = 'hstore' },
87 { column = 'nodes', type = 'text', sql_type = 'bigint[]', not_null = true },
88 { column = 'geometry', type = 'linestring', projection = 'WGS84', not_null = true },
91 { column = 'nodes', method = 'gin' }
94 place_associated_street = {
95 ids = { type = 'relation', id_column = 'relation_id' },
97 { column = 'member_type', type = 'text', not_null = true },
98 { column = 'member_id', type = 'int8', not_null = true },
99 { column = 'member_role', type = 'text', not_null = true }
102 { column = { 'member_type', 'member_id' }, method = 'btree' }
107 local insert_row = {}
108 local script_path = debug.getinfo(1, "S").source:match("@?(.*/)")
109 local PRESETS = loadfile(script_path .. 'presets.lua')()
111 for table_name, table_definition in pairs(table_definitions) do
112 table_definition.name = table_name
113 table_definition.data_tablespace = os.getenv("NOMINATIM_TABLESPACE_PLACE_DATA")
114 table_definition.index_tablespace = os.getenv("NOMINATIM_TABLESPACE_PLACE_INDEX")
117 themepark:add_table(table_definition)
118 insert_row[table_name] = function(columns)
119 themepark:insert(table_name, columns, {}, {})
122 local place_table = osm2pgsql.define_table(table_definition)
123 insert_row[table_name] = function(columns)
124 place_table:insert(columns)
129 ------------ Geometry functions for relations ---------------------
131 function module.relation_as_multipolygon(o)
132 return o:as_multipolygon()
135 function module.relation_as_multiline(o)
136 return o:as_multilinestring():line_merge()
140 module.RELATION_TYPES = {
141 multipolygon = module.relation_as_multipolygon,
142 boundary = module.relation_as_multipolygon,
143 waterway = module.relation_as_multiline
146 --------- Built-in place transformation functions --------------------------
148 local PlaceTransform = {}
150 -- Special transform meanings which are interpreted elsewhere
151 PlaceTransform.fallback = 'fallback'
152 PlaceTransform.postcode_area = 'postcode_area'
153 PlaceTransform.delete = 'delete'
154 PlaceTransform.extra = 'extra'
156 -- always: unconditionally use that place
157 function PlaceTransform.always(place)
161 -- never: unconditionally drop the place
162 function PlaceTransform.never()
166 -- named: use the place if it has a fully-qualified name
167 function PlaceTransform.named(place)
168 if place.has_name then
173 -- named_with_key: use place if there is a name with the main key prefix
174 function PlaceTransform.named_with_key(place, k)
175 local prefix = k .. ':name'
177 for namek, namev in pairs(place.intags) do
178 if namek:sub(1, #prefix) == prefix
179 and (#namek == #prefix
180 or namek:sub(#prefix + 1, #prefix + 1) == ':') then
181 place.names[namek:sub(#k + 2)] = namev
192 ----------------- other helper functions -----------------------------
194 local function lookup_prefilter_classification(k, v)
196 local desc = MAIN_KEYS[k]
197 local fullmatch = desc and (desc[v] or desc[1])
198 if fullmatch ~= nil then
202 for slen, slist in pairs(PRE_FILTER.suffix) do
204 local group = slist[k:sub(-slen)]
211 for slen, slist in pairs(PRE_FILTER.prefix) do
213 local group = slist[k:sub(1, slen)]
222 local function merge_filters_into_main(group, keys, tags)
224 for _, key in pairs(keys) do
225 -- ignore suffix and prefix matches
226 if key:sub(1, 1) ~= '*' and key:sub(#key, #key) ~= '*' then
227 if MAIN_KEYS[key] == nil then
230 MAIN_KEYS[key][1] = group
236 for key, values in pairs(tags) do
237 if MAIN_KEYS[key] == nil then
240 for _, v in pairs(values) do
241 MAIN_KEYS[key][v] = group
248 local function remove_group_from_main(group)
249 for key, values in pairs(MAIN_KEYS) do
250 for _, ttype in pairs(values) do
251 if ttype == group then
255 if next(values) == nil then
262 local function add_pre_filter(data)
263 for group, keys in pairs(data) do
264 for _, key in pairs(keys) do
265 local klen = #key - 1
266 if key:sub(1, 1) == '*' then
268 if PRE_FILTER.suffix[klen] == nil then
269 PRE_FILTER.suffix[klen] = {}
271 PRE_FILTER.suffix[klen][key:sub(2)] = group
273 elseif key:sub(#key, #key) == '*' then
274 if PRE_FILTER.prefix[klen] == nil then
275 PRE_FILTER.prefix[klen] = {}
277 PRE_FILTER.prefix[klen][key:sub(1, klen)] = group
283 ------------- Place class ------------------------------------------
286 Place.__index = Place
288 -- ltree labels: validate-or-fallback matching Photon's CATEGORY_PATTERN.
289 -- Hyphens replaced with underscore for PG < 16 ltree compat.
290 -- Any other invalid char -> fall back to 'yes'.
291 -- https://www.postgresql.org/message-id/E1pDtub-002Nio-Tv%40gemulon.postgresql.org
292 local function sanitize_label(s)
293 if s == nil or s == '' then return 'yes' end
294 if s:match('[^A-Za-z0-9_-]') then
297 return s:gsub('-', '_')
300 -- Build an ltree-compatible category string: osm.<key>.<value>.
301 -- Returns nil if the key cannot be sanitized to a valid ltree label.
302 local function get_category(k, v)
303 if k == nil or k == '' or k:match('[^A-Za-z0-9_-]') then
306 return 'osm.' .. sanitize_label(k) .. '.' .. sanitize_label(v)
310 function Place.new(object, geom_func)
311 local self = setmetatable({}, Place)
313 self.geom_func = geom_func
315 self.admin_level = tonumber(self.object.tags.admin_level or 15) or 15
316 if self.admin_level == nil
317 or self.admin_level <= 0 or self.admin_level > 15
318 or math.floor(self.admin_level) ~= self.admin_level then
319 self.admin_level = 15
322 self.has_name = false
329 local has_main_tags = false
330 for k, v in pairs(self.object.tags) do
331 local group = lookup_prefilter_classification(k, v)
332 if group == 'extra' then
333 self.extratags[k] = v
334 elseif group ~= 'delete' then
342 if not has_main_tags then
343 -- no interesting tags, don't bother processing
350 function Place:clean(data)
351 for k, v in pairs(self.intags) do
352 if data.delete ~= nil and data.delete(k, v) then
354 elseif data.extra ~= nil and data.extra(k, v) then
355 self.extratags[k] = v
361 function Place:delete(data)
362 if data.match ~= nil then
363 for k, v in pairs(self.intags) do
364 if data.match(k, v) then
371 function Place:grab_extratags(data)
374 if data.match ~= nil then
375 for k, v in pairs(self.intags) do
376 if data.match(k, v) then
378 self.extratags[k] = v
387 local function strip_address_prefix(k)
388 if k:sub(1, 5) == 'addr:' then
392 if k:sub(1, 6) == 'is_in:' then
400 function Place:grab_address_parts(data)
403 if data.groups ~= nil then
404 for k, v in pairs(self.intags) do
405 local atype = data.groups(k, v)
408 if atype == 'main' then
410 self.address[strip_address_prefix(k)] = v
412 elseif atype == 'extra' then
413 self.address[strip_address_prefix(k)] = v
415 self.address[atype] = v
426 function Place:grab_name_parts(data)
427 local fallback = false
429 if data.groups ~= nil then
430 for k, v in pairs(self.intags) do
431 local atype = data.groups(k, v)
436 if atype == 'main' then
438 elseif atype == 'house' then
452 function Place:geometry_is_valid()
453 if self.geometry == nil then
454 self.geometry = self.geom_func(self.object)
456 if self.geometry == nil or self.geometry:is_null() then
457 self.geometry = false
464 return self.geometry ~= false
469 function Place:clone(data)
470 local cp = setmetatable({}, Place)
471 cp.object = self.object
472 cp.geometry = data.geometry or self.geometry
473 cp.geom_func = self.geom_func
474 cp.intags = data.intags or self.intags
475 cp.admin_level = data.admin_level or self.admin_level
476 cp.names = data.names or self.names
477 cp.address = data.address or self.address
478 cp.extratags = data.extratags or self.extratags
484 function module.tag_match(data)
485 if data == nil or next(data) == nil then
489 local fullmatches = {}
490 local key_prefixes = {}
491 local key_suffixes = {}
493 if data.keys ~= nil then
494 for _, key in pairs(data.keys) do
495 if key:sub(1, 1) == '*' then
497 if key_suffixes[#key - 1] == nil then
498 key_suffixes[#key - 1] = {}
500 key_suffixes[#key - 1][key:sub(2)] = true
502 elseif key:sub(#key, #key) == '*' then
503 if key_prefixes[#key - 1] == nil then
504 key_prefixes[#key - 1] = {}
506 key_prefixes[#key - 1][key:sub(1, #key - 1)] = true
508 fullmatches[key] = true
513 if data.tags ~= nil then
514 for k, vlist in pairs(data.tags) do
515 if fullmatches[k] == nil then
517 for _, v in pairs(vlist) do
518 fullmatches[k][v] = true
524 return function (k, v)
525 if fullmatches[k] ~= nil and (fullmatches[k] == true or fullmatches[k][v] ~= nil) then
529 for slen, slist in pairs(key_suffixes) do
530 if #k >= slen and slist[k:sub(-slen)] ~= nil then
535 for slen, slist in pairs(key_prefixes) do
536 if #k >= slen and slist[k:sub(1, slen)] ~= nil then
546 function module.tag_group(data)
547 if data == nil or next(data) == nil then
551 local fullmatches = {}
552 local key_prefixes = {}
553 local key_suffixes = {}
555 for group, tags in pairs(data) do
556 for _, key in pairs(tags) do
557 if key:sub(1, 1) == '*' then
559 if key_suffixes[#key - 1] == nil then
560 key_suffixes[#key - 1] = {}
562 key_suffixes[#key - 1][key:sub(2)] = group
564 elseif key:sub(#key, #key) == '*' then
565 if key_prefixes[#key - 1] == nil then
566 key_prefixes[#key - 1] = {}
568 key_prefixes[#key - 1][key:sub(1, #key - 1)] = group
570 fullmatches[key] = group
576 local val = fullmatches[k]
581 for slen, slist in pairs(key_suffixes) do
583 val = slist[k:sub(-slen)]
590 for slen, slist in pairs(key_prefixes) do
592 val = slist[k:sub(1, slen)]
601 -- Returns prefix part of the keys, and reject suffix matching keys
602 local function process_key(key)
603 if key:sub(1, 1) == '*' then
606 if key:sub(#key, #key) == '*' then
607 return key:sub(1, #key - 2)
612 -- Process functions for all data types
613 function module.process_node(object)
614 if ENTRANCE_FUNCTION ~= nil then
615 local entrance_info = ENTRANCE_FUNCTION(object)
616 if entrance_info ~= nil then
617 insert_row.place_entrance{
618 type = entrance_info.entrance,
619 extratags = entrance_info.extratags,
620 geometry = object:as_point()
625 local function geom_func(o)
629 module.process_tags(Place.new(object, geom_func))
632 function module.process_way(object)
634 local function geom_func(o)
635 local geom = o:as_polygon()
637 if geom:is_null() then
638 geom = o:as_linestring()
639 if geom:is_null() or geom:length() > 30 then
647 module.process_tags(Place.new(object, geom_func))
650 function module.process_relation(object)
651 if object.tags.type == 'associatedStreet' then
652 local has_street = false
653 for _, member in ipairs(object.members) do
654 -- Streets can only be ways or relations, not nodes
655 if member.role == 'street' and (member.type == 'w' or member.type == 'r') then
661 for _, member in ipairs(object.members) do
662 -- Only insert streets that are ways or relations
663 if member.role == 'street' and (member.type == 'w' or member.type == 'r') then
664 insert_row.place_associated_street{
665 member_type = member.type:upper(),
666 member_id = member.ref,
667 member_role = member.role
669 elseif member.role == 'house' then
670 insert_row.place_associated_street{
671 member_type = member.type:upper(),
672 member_id = member.ref,
673 member_role = member.role
680 local geom_func = module.RELATION_TYPES[object.tags.type]
682 if geom_func ~= nil then
683 module.process_tags(Place.new(object, geom_func))
687 -- The process functions are used by default by osm2pgsql.
689 themepark:add_proc('node', module.process_node)
690 themepark:add_proc('way', module.process_way)
691 themepark:add_proc('relation', module.process_relation)
693 osm2pgsql.process_node = module.process_node
694 osm2pgsql.process_way = module.process_way
695 osm2pgsql.process_relation = module.process_relation
698 -- Build extratags for a merged row: filter via EXTRATAGS_FILTER,
699 -- remove sibling main tags (they belong in categories, not extratags),
700 -- then add any required extratags (wikipedia, wikidata, etc.).
701 local function build_extratags(place, k, v)
702 local extra = EXTRATAGS_FILTER(place, k, v) or {}
703 for ek, ev in pairs(extra) do
704 local ktable = MAIN_KEYS[ek]
705 if ktable ~= nil then
706 local transform = ktable[ev] or ktable[1]
707 if type(transform) == 'function' then
712 for tk, tv in pairs(place.object.tags) do
713 if REQUIRED_EXTRATAGS_FILTER(tk, tv) and extra[tk] == nil then
717 if next(extra) == nil then return nil end
721 function module.process_tags(o)
722 if next(o.intags) == nil then
723 return -- shortcut when pre-filtering has removed all tags
727 local needs_address_fallback = o:grab_name_parts{groups=NAME_FILTER}
730 if o:grab_address_parts{groups=ADDRESS_FILTER} > 0 and not needs_address_fallback then
731 needs_address_fallback = true
733 if o.address.country ~= nil and #o.address.country ~= 2 then
734 o.address['country'] = nil
737 if o.address.interpolation ~= nil and o.address.housenumber == nil
738 and o.object.type == 'way' and o.object.nodes ~= nil then
739 local extra_addr = nil
740 for k, v in pairs(o.address) do
741 if k ~= 'interpolation' then
742 if extra_addr == nil then
749 insert_row.place_interpolation{
750 type = o.address.interpolation,
751 address = extra_addr,
752 nodes = '{' .. table.concat(o.object.nodes, ',') .. '}',
753 geometry = o.object:as_linestring()
757 -- Collect categories from main keys into a single row.
758 local categories = {}
759 local main_class, main_type = nil, nil
760 local merged_extratags = nil
761 local postcode_collect = false
762 local tag_fallback = nil
764 for k, v in pairs(o.intags) do
765 local ktable = MAIN_KEYS[k]
767 local ktype = ktable[v] or ktable[1]
768 if type(ktype) == 'function' then
769 local result = ktype(o, k, v)
771 -- If transform returned a clone (lock_transform, etc.),
772 -- use its names for the final row
774 o.names = result.names
778 local cat = get_category(k, v)
780 table.insert(categories, cat)
782 -- TODO: alphabetical winner selection is a temporary heuristic.
783 -- Later we will choose by rankability (e.g. avoid boundary on non-area ways)
784 -- or by explicit user/config priority or idk.
787 or (k == main_class and v < main_type) then
793 elseif ktype == 'postcode_area' then
794 postcode_collect = true
795 if o.object.type == 'relation'
796 and o.address.postcode ~= nil
797 and o:geometry_is_valid() then
798 insert_row.place_postcode{
799 postcode = o.address.postcode,
800 centroid = o.geometry:centroid(),
801 geometry = o.geometry
804 elseif ktype == 'fallback' and o.has_name then
805 tag_fallback = {k, v}
810 -- Build extratags once after the loop (filters out main keys automatically)
811 merged_extratags = build_extratags(o, nil, nil)
813 -- Handle tag-based fallback: always add category, set class/type only if sole producer
814 if tag_fallback ~= nil then
815 local fk, fv = tag_fallback[1], tag_fallback[2]
816 local was_empty = (#categories == 0)
817 local cat = get_category(fk, fv)
819 table.insert(categories, cat)
827 -- Handle address/house fallback if no main tags produced categories
828 if #categories == 0 then
829 if needs_address_fallback then
830 if next(o.names) ~= nil and NAMES.house ~= nil then
832 for k, v in pairs(o.names) do
833 if NAME_FILTER(k, v) == 'house' then
840 table.insert(categories, 'osm.place.house')
843 elseif POSTCODE_FALLBACK and not postcode_collect
844 and o.address.postcode ~= nil
845 and o:geometry_is_valid() then
846 insert_row.place_postcode{
847 postcode = o.address.postcode,
848 centroid = o.geometry:centroid()
853 -- Build and insert single row with all collected categories
854 if #categories > 0 and o:geometry_is_valid() then
858 admin_level = o.admin_level,
859 name = next(o.names) and o.names,
860 address = next(o.address) and o.address,
861 extratags = merged_extratags and next(merged_extratags) and merged_extratags,
862 geometry = o.geometry,
863 categories = '{' .. table.concat(categories, ',') .. '}'
868 --------- Extratags post-processing functions ---------------
870 local function default_extratags_filter(p, k)
874 EXTRATAGS_FILTER = default_extratags_filter
875 REQUIRED_EXTRATAGS_FILTER = module.tag_match(PRESETS.EXTRATAGS)
877 --------- Convenience functions for simple style configuration -----------------
879 function module.set_prefilters(data)
880 remove_group_from_main('delete')
881 merge_filters_into_main('delete', data.delete_keys, data.delete_tags)
883 remove_group_from_main('extra')
884 merge_filters_into_main('extra', data.extra_keys, data.extra_tags)
886 PRE_FILTER = {prefix = {}, suffix = {}}
887 add_pre_filter{delete = data.delete_keys, extra = data.extra_keys}
891 function module.ignore_keys(data)
892 if type(data) == 'string' then
894 data = PRESETS.IGNORE_KEYS[data]
896 error('Unknown preset for ignored keys: ' .. preset)
899 merge_filters_into_main('delete', data)
900 add_pre_filter{delete = data}
904 function module.add_for_extratags(data)
905 if type(data) == 'string' then
907 data = PRESETS.IGNORE_KEYS[data]
909 error('Unknown preset for extratags: ' .. preset)
912 merge_filters_into_main('extra', data)
913 add_pre_filter{extra = data}
917 function module.set_main_tags(data)
918 for key, values in pairs(MAIN_KEYS) do
919 for _, ttype in pairs(values) do
920 if ttype == 'fallback' or type(ttype) == 'function' then
924 if next(values) == nil then
928 module.modify_main_tags(data)
932 function module.modify_main_tags(data)
933 if type(data) == 'string' then
935 if data:sub(1, 7) == 'street/' then
936 data = PRESETS.MAIN_TAGS_STREETS[data:sub(8)]
937 elseif data:sub(1, 4) == 'poi/' then
938 data = PRESETS.MAIN_TAGS_POIS(data:sub(5))
940 data = PRESETS.MAIN_TAGS[data]
943 error('Unknown preset for main tags: ' .. preset)
947 for k, v in pairs(data) do
948 if MAIN_KEYS[k] == nil then
951 if type(v) == 'function' then
953 elseif type(v) == 'string' then
954 MAIN_KEYS[k][1] = PlaceTransform[v]
955 elseif type(v) == 'table' then
956 for subk, subv in pairs(v) do
957 if type(subv) == 'function' then
958 MAIN_KEYS[k][subk] = subv
960 MAIN_KEYS[k][subk] = PlaceTransform[subv]
968 function module.modify_name_tags(data)
969 if type(data) == 'string' then
971 data = PRESETS.NAME_TAGS[data]
973 error('Unknown preset for name keys: ' .. preset)
977 for k,v in pairs(data) do
984 NAME_FILTER = module.tag_group(NAMES)
985 remove_group_from_main('fallback:name')
986 if data.house ~= nil then
987 merge_filters_into_main('fallback:name', data.house)
992 function module.set_name_tags(data)
994 module.modify_name_tags(data)
998 function module.set_address_tags(data)
1000 module.modify_address_tags(data)
1004 function module.modify_address_tags(data)
1005 if type(data) == 'string' then
1007 data = PRESETS.ADDRESS_TAGS[data]
1009 error('Unknown preset for address keys: ' .. preset)
1013 for k, v in pairs(data) do
1014 if k == 'postcode_fallback' then
1015 POSTCODE_FALLBACK = v
1016 elseif next(v) == nil then
1017 ADDRESS_TAGS[k] = nil
1023 ADDRESS_FILTER = module.tag_group(ADDRESS_TAGS)
1025 remove_group_from_main('fallback:address')
1026 merge_filters_into_main('fallback:address', data.main)
1027 merge_filters_into_main('fallback:address', data.interpolation)
1028 remove_group_from_main('fallback:postcode')
1029 if POSTCODE_FALLBACK then
1030 merge_filters_into_main('fallback:postcode', data.postcode)
1035 function module.set_address_tags(data)
1036 ADDRESS_TAGS_SOURCE = {}
1037 module.modify_address_tags(data)
1041 function module.set_postcode_fallback(enable)
1042 if POSTCODE_FALLBACK ~= enable then
1043 remove_group_from_main('fallback:postcode')
1045 merge_filters_into_main('fallback:postcode', ADDRESS_TAGS.postcode)
1048 POSTCODE_FALLBACK = enable
1052 function module.set_unused_handling(data)
1053 if type(data) == 'function' then
1054 EXTRATAGS_FILTER = data
1055 elseif data == nil then
1056 EXTRATAGS_FILTER = default_extratags_filter
1057 elseif data.extra_keys == nil and data.extra_tags == nil then
1058 local delfilter = module.tag_match{keys = data.delete_keys, tags = data.delete_tags}
1059 EXTRATAGS_FILTER = function (p, k)
1061 for kin, vin in pairs(p.intags) do
1062 if kin ~= k and not delfilter(kin, vin) then
1066 if next(extra) == nil then
1069 for kextra, vextra in pairs(p.extratags) do
1070 extra[kextra] = vextra
1074 elseif data.delete_keys == nil and data.delete_tags == nil then
1075 local incfilter = module.tag_match{keys = data.extra_keys, tags = data.extra_tags}
1076 EXTRATAGS_FILTER = function (p, k)
1078 for kin, vin in pairs(p.intags) do
1079 if kin ~= k and incfilter(kin, vin) then
1083 if next(extra) == nil then
1086 for kextra, vextra in pairs(p.extratags) do
1087 extra[kextra] = vextra
1092 error("unused handler can have only 'extra_keys' or 'delete_keys' set.")
1096 function module.set_relation_types(data)
1097 module.RELATION_TYPES = {}
1099 if v == 'multipolygon' then
1100 module.RELATION_TYPES[k] = module.relation_as_multipolygon
1101 elseif v == 'multiline' then
1102 module.RELATION_TYPES[k] = module.relation_as_multiline
1107 function module.set_entrance_filter(data)
1108 if data == nil or type(data) == 'function' then
1109 ENTRANCE_FUNCTION = data
1113 if type(data) == 'string' then
1115 data = PRESETS.ENTRANCE_TABLE[data]
1117 error('Unknown preset for entrance table: ' .. preset)
1121 ENTRANCE_FUNCTION = nil
1123 if data.main_tags ~= nil and next(data.main_tags) ~= nil then
1124 if data.extra_include ~= nil and next(data.extra_include) == nil then
1125 -- shortcut: no extra tags requested
1126 ENTRANCE_FUNCTION = function(o)
1127 for _, v in ipairs(data.main_tags) do
1128 if o.tags[v] ~= nil then
1129 return {entrance = o.tags[v]}
1135 if data.extra_include ~= nil then
1137 for _, v in pairs(data.extra_include) do
1140 if data.extra_exclude ~= nil then
1141 for _, v in pairs(data.extra_exclude) do
1145 for _, v in pairs(data.main_tags) do
1149 ENTRANCE_FUNCTION = function(o)
1150 for _, v in ipairs(data.main_tags) do
1151 if o.tags[v] ~= nil then
1152 local entrance = o.tags[v]
1154 for k, v in pairs(tags) do
1155 extra[k] = o.tags[k]
1157 if next(extra) == nil then
1160 return {entrance = entrance, extratags = extra}
1168 if data.extra_exclude ~= nil then
1169 for _, v in pairs(data.extra_exclude) do
1173 for _, v in pairs(data.main_tags) do
1177 ENTRANCE_FUNCTION = function(o)
1178 for _, v in ipairs(data.main_tags) do
1179 if o.tags[v] ~= nil then
1180 local entrance = o.tags[v]
1182 for k, v in pairs(o.tags) do
1183 if notags[k] ~= 1 then
1187 if next(extra) == nil then
1190 return {entrance = entrance, extratags = extra}
1201 function module.get_taginfo()
1202 return {main = MAIN_KEYS, name = NAMES, address = ADDRESS_TAGS}