-- Core functions for Nominatim import flex style.
--
+local module = {}
-- The single place table.
place_table = osm2pgsql.define_table{
for k, v in pairs(self.object.tags) do
local atype = data.groups(k, v)
- if atype == 'main' then
- self.has_name = true
- self.address[strip_address_prefix(k)] = v
- count = count + 1
- elseif atype == 'extra' then
- self.address[strip_address_prefix(k)] = v
- elseif atype ~= nil then
- self.address[atype] = v
+ if atype ~= nil then
+ if atype == 'main' then
+ self.has_name = true
+ self.address[strip_address_prefix(k)] = v
+ count = count + 1
+ elseif atype == 'extra' then
+ self.address[strip_address_prefix(k)] = v
+ else
+ self.address[atype] = v
+ end
+ self.object.tags[k] = nil
end
end
end
end
-function tag_match(data)
+function module.tag_match(data)
if data == nil or next(data) == nil then
return nil
end
end
-function key_group(data)
+function module.tag_group(data)
if data == nil or next(data) == nil then
return nil
end
return o:as_point()
end
- process_tags(Place.new(object, geom_func))
+ module.process_tags(Place.new(object, geom_func))
end
function osm2pgsql.process_way(object)
return geom
end
- process_tags(Place.new(object, geom_func))
+ module.process_tags(Place.new(object, geom_func))
end
-function relation_as_multipolygon(o)
+function module.relation_as_multipolygon(o)
return o:as_multipolygon()
end
-function relation_as_multiline(o)
+function module.relation_as_multiline(o)
return o:as_multilinestring():line_merge()
end
function osm2pgsql.process_relation(object)
- local geom_func = RELATION_TYPES[object.tags.type]
+ local geom_func = module.RELATION_TYPES[object.tags.type]
if geom_func ~= nil then
- process_tags(Place.new(object, geom_func))
+ module.process_tags(Place.new(object, geom_func))
end
end
-function process_tags(o)
- o:clean{delete = PRE_DELETE, extra = PRE_EXTRAS}
+function module.process_tags(o)
+ o:clean{delete = module.PRE_DELETE, extra = module.PRE_EXTRAS}
-- Exception for boundary/place double tagging
if o.object.tags.boundary == 'administrative' then
end
-- name keys
- local fallback = o:grab_name_parts{groups=NAMES}
+ local fallback = o:grab_name_parts{groups=module.NAMES}
-- address keys
- if o:grab_address_parts{groups=ADDRESS_TAGS} > 0 and fallback == nil then
+ if o:grab_address_parts{groups=module.ADDRESS_TAGS} > 0 and fallback == nil then
fallback = {'place', 'house', 'always'}
end
if o.address.country ~= nil and #o.address.country ~= 2 then
end
if o.address.interpolation ~= nil then
- o:write_place('place', 'houses', 'always', SAVE_EXTRA_MAINS)
+ o:write_place('place', 'houses', 'always', module.SAVE_EXTRA_MAINS)
return
end
- o:clean{delete = POST_DELETE, extra = POST_EXTRAS}
+ o:clean{delete = module.POST_DELETE, extra = module.POST_EXTRAS}
-- collect main keys
for k, v in pairs(o.object.tags) do
- local ktype = MAIN_KEYS[k]
+ local ktype = module.MAIN_KEYS[k]
if ktype == 'fallback' then
if o.has_name then
fallback = {k, v, 'named'}
end
elseif ktype ~= nil then
- o:write_place(k, v, MAIN_KEYS[k], SAVE_EXTRA_MAINS)
+ o:write_place(k, v,module.MAIN_KEYS[k], module.SAVE_EXTRA_MAINS)
end
end
if fallback ~= nil and o.num_entries == 0 then
- o:write_place(fallback[1], fallback[2], fallback[3], SAVE_EXTRA_MAINS)
+ o:write_place(fallback[1], fallback[2], fallback[3], module.SAVE_EXTRA_MAINS)
end
end
+------ defaults --------------
+
+module.RELATION_TYPES = {
+ multipolygon = module.relation_as_multipolygon,
+ boundary = module.relation_as_multipolygon,
+ waterway = module.relation_as_multiline
+}
+
+return module
-require('flex-base')
+flex = require('flex-base')
-RELATION_TYPES = {
- multipolygon = relation_as_multipolygon,
- boundary = relation_as_multipolygon,
- waterway = relation_as_multiline
-}
-
-MAIN_KEYS = {
+flex.MAIN_KEYS = {
building = 'fallback',
emergency = 'always',
healthcare = 'fallback',
}
-PRE_DELETE = tag_match{keys = {'note', 'note:*', 'source', 'source*', 'attribution',
+flex.PRE_DELETE = flex.tag_match{keys = {'note', 'note:*', 'source', 'source*', 'attribution',
'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*',
'nhd:*', 'gnis:*', 'geobase:*', 'KSJ2:*', 'yh:*',
'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*',
boundary = {'place'}}
}
-POST_DELETE = tag_match{keys = {'tiger:*'}}
+flex.POST_DELETE = flex.tag_match{keys = {'tiger:*'}}
-PRE_EXTRAS = tag_match{keys = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
+flex.PRE_EXTRAS = flex.tag_match{keys = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
'name:etymology', 'name:signed', 'name:botanical',
'wikidata', '*:wikidata',
'addr:street:name', 'addr:street:type'}
}
-NAMES = key_group{main = {'name', 'name:*',
+flex.NAMES = flex.tag_group{main = {'name', 'name:*',
'int_name', 'int_name:*',
'nat_name', 'nat_name:*',
'reg_name', 'reg_name:*',
house = {'addr:housename'}
}
-ADDRESS_TAGS = key_group{main = {'addr:housenumber',
+flex.ADDRESS_TAGS = flex.tag_group{main = {'addr:housenumber',
'addr:conscriptionnumber',
'addr:streetnumber'},
extra = {'addr:*', 'is_in:*', 'tiger:county'},
interpolation = {'addr:interpolation'}
}
-SAVE_EXTRA_MAINS = true
+flex.SAVE_EXTRA_MAINS = true