mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 19:07:58 +00:00
put postcodes in extra table on import
This commit is contained in:
@@ -65,7 +65,19 @@ local table_definitions = {
|
||||
{ column = 'geometry', type = 'geometry', projection = 'WGS84', not_null = true }
|
||||
},
|
||||
indexes = {}
|
||||
}
|
||||
},
|
||||
place_postcode = {
|
||||
ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
|
||||
columns = {
|
||||
{ column = 'postcode', type = 'text', not_null = true },
|
||||
{ column = 'country_code', type = 'text' },
|
||||
{ column = 'centroid', type = 'point', projection = 'WGS84', not_null = true },
|
||||
{ column = 'geometry', type = 'geometry', projection = 'WGS84' }
|
||||
},
|
||||
indexes = {
|
||||
{ column = 'postcode', method = 'btree' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local insert_row = {}
|
||||
@@ -113,6 +125,7 @@ local PlaceTransform = {}
|
||||
|
||||
-- Special transform meanings which are interpreted elsewhere
|
||||
PlaceTransform.fallback = 'fallback'
|
||||
PlaceTransform.postcode_area = 'postcode_area'
|
||||
PlaceTransform.delete = 'delete'
|
||||
PlaceTransform.extra = 'extra'
|
||||
|
||||
@@ -419,11 +432,25 @@ function Place:write_place(k, v, mfunc)
|
||||
return 0
|
||||
end
|
||||
|
||||
function Place:write_row(k, v)
|
||||
|
||||
function Place:geometry_is_valid()
|
||||
if self.geometry == nil then
|
||||
self.geometry = self.geom_func(self.object)
|
||||
|
||||
if self.geometry == nil or self.geometry:is_null() then
|
||||
self.geometry = false
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
if self.geometry == nil or self.geometry:is_null() then
|
||||
|
||||
return self.geometry ~= false
|
||||
end
|
||||
|
||||
|
||||
function Place:write_row(k, v)
|
||||
if not self:geometry_is_valid() then
|
||||
return 0
|
||||
end
|
||||
|
||||
@@ -675,9 +702,6 @@ function module.process_tags(o)
|
||||
if o.address.country ~= nil and #o.address.country ~= 2 then
|
||||
o.address['country'] = nil
|
||||
end
|
||||
if POSTCODE_FALLBACK and fallback == nil and o.address.postcode ~= nil then
|
||||
fallback = {'place', 'postcode', PlaceTransform.always}
|
||||
end
|
||||
|
||||
if o.address.interpolation ~= nil then
|
||||
o:write_place('place', 'houses', PlaceTransform.always)
|
||||
@@ -685,20 +709,41 @@ function module.process_tags(o)
|
||||
end
|
||||
|
||||
-- collect main keys
|
||||
local postcode_collect = false
|
||||
for k, v in pairs(o.intags) do
|
||||
local ktable = MAIN_KEYS[k]
|
||||
if ktable then
|
||||
local ktype = ktable[v] or ktable[1]
|
||||
if type(ktype) == 'function' then
|
||||
o:write_place(k, v, ktype)
|
||||
elseif ktype == 'postcode_area' then
|
||||
postcode_collect = true
|
||||
if o.object.type == 'relation'
|
||||
and o.address.postcode ~= nil
|
||||
and o:geometry_is_valid() then
|
||||
insert_row.place_postcode{
|
||||
postcode = o.address.postcode,
|
||||
centroid = o.geometry:centroid(),
|
||||
geometry = o.geometry
|
||||
}
|
||||
end
|
||||
elseif ktype == 'fallback' and o.has_name then
|
||||
fallback = {k, v, PlaceTransform.named}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fallback ~= nil and o.num_entries == 0 then
|
||||
o:write_place(fallback[1], fallback[2], fallback[3])
|
||||
if o.num_entries == 0 then
|
||||
if fallback ~= nil then
|
||||
o:write_place(fallback[1], fallback[2], fallback[3])
|
||||
elseif POSTCODE_FALLBACK and not postcode_collect
|
||||
and o.address.postcode ~= nil
|
||||
and o:geometry_is_valid() then
|
||||
insert_row.place_postcode{
|
||||
postcode = o.address.postcode,
|
||||
centroid = o.geometry:centroid()
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ module.MAIN_TAGS.all_boundaries = {
|
||||
place = 'delete',
|
||||
land_area = 'delete',
|
||||
protected_area = 'fallback',
|
||||
postal_code = 'always'},
|
||||
postal_code = 'postcode_area'},
|
||||
landuse = 'fallback',
|
||||
place = 'always'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user