Skip to content

Commit

Permalink
Merge pull request #3615 from lonvia/overhaul-osm2pgsql-style
Browse files Browse the repository at this point in the history
Overhaul osm2pgsql style
  • Loading branch information
lonvia authored Dec 16, 2024
2 parents 639630d + 2535780 commit 9058dab
Show file tree
Hide file tree
Showing 39 changed files with 2,150 additions and 1,343 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ jobs:
- name: Prepare import environment
run: |
mv Nominatim/test/testdb/apidb-test-data.pbf test.pbf
mv Nominatim/settings/flex-base.lua flex-base.lua
mv Nominatim/settings/import-extratags.lua import-extratags.lua
mv Nominatim/settings/taginfo.lua taginfo.lua
rm -rf Nominatim
mkdir data-env-reverse
working-directory: /home/nominatim
Expand All @@ -205,7 +202,7 @@ jobs:
working-directory: /home/nominatim/nominatim-project

- name: Print taginfo
run: lua taginfo.lua
run: lua ./nominatim-venv/lib/*/site-packages/nominatim_db/resources/lib-lua/taginfo.lua
working-directory: /home/nominatim

- name: Collect host OS information
Expand Down
583 changes: 357 additions & 226 deletions docs/customize/Import-Styles.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/customize/Special-Phrases.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ columns:

* **phrase**: the keyword to look for
* **class**: key of the main tag of the place to find
(see [principal tags in import style](Import-Styles.md#set_main_tags-principal-tags)
(see [Import styles](Import-Styles.md#how-processing-works)
* **type**: value of the main tag
* **operator**: type of special phrase, may be one of:
* *in*: place is within the place defined by the search term (e.g. "_Hotels in_ Berlin")
Expand Down
4 changes: 2 additions & 2 deletions docs/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
display: none!important
}

.wy-nav-content {
max-width: 900px!important
.md-content {
max-width: 800px
}

table {
Expand Down
14 changes: 14 additions & 0 deletions lib-lua/flex-base.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- This is just an alias for the Nominatim themepark theme module
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'

if topic_file == nil then
error('Cannot find topic: ' .. name)
end

loadfile(topic_file)(nil, flex, cfg or {})
end

return flex
6 changes: 6 additions & 0 deletions lib-lua/import-address.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This is just an alias for the Nominatim themepark address topic
local flex = require('flex-base')

flex.load_topic('address')

return flex
6 changes: 6 additions & 0 deletions lib-lua/import-admin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This is just an alias for the Nominatim themepark admin topic
local flex = require('flex-base')

flex.load_topic('admin')

return flex
6 changes: 6 additions & 0 deletions lib-lua/import-extratags.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This is just an alias for the Nominatim themepark full topic
local flex = require('flex-base')

flex.load_topic('full', {with_extratags = true})

return flex
6 changes: 6 additions & 0 deletions lib-lua/import-full.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This is just an alias for the Nominatim themepark full topic
local flex = require('flex-base')

flex.load_topic('full')

return flex
6 changes: 6 additions & 0 deletions lib-lua/import-street.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This is just an alias for the Nominatim themepark street topic
local flex = require('flex-base')

flex.load_topic('street')

return flex
118 changes: 118 additions & 0 deletions lib-lua/taginfo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
-- Prints taginfo project description in the standard output
--

-- create fake "osm2pgsql" table for flex-base, originally created by the main C++ program
osm2pgsql = {}
function osm2pgsql.define_table(...) end

-- provide path to flex-style lua file
package.path = arg[0]:match("(.*/)") .. "?.lua;" .. package.path
local flex = require('import-' .. (arg[1] or 'extratags'))
local json = require ('dkjson')

local NAME_DESCRIPTIONS = {
'Searchable auxiliary name of the place',
main = 'Searchable primary name of the place',
house = 'House name part of an address, searchable'
}
local ADDRESS_DESCRIPTIONS = {
'Used to determine the address of a place',
main = 'Primary key for an address point',
postcode = 'Used to determine the postcode of a place',
country = 'Used to determine country of a place (only if written as two-letter code)',
interpolation = 'Primary key for an address interpolation line'
}

------------ helper functions ---------------------
-- Sets the key order for the resulting JSON table
local function set_keyorder(table, order)
setmetatable(table, {
__jsonorder = order
})
end

local function get_key_description(key, description)
local desc = {}
desc.key = key
desc.description = description
set_keyorder(desc, {'key', 'description'})
return desc
end

local function get_key_value_description(key, value, description)
local desc = {key = key, value = value, description = description}
set_keyorder(desc, {'key', 'value', 'description'})
return desc
end

local function group_table_to_keys(tags, data, descriptions)
for group, values in pairs(data) do
local desc = descriptions[group] or descriptions[1]
for _, key in pairs(values) do
if key:sub(1, 1) ~= '*' and key:sub(#key, #key) ~= '*' then
table.insert(tags, get_key_description(key, desc))
end
end
end
end

-- Prints the collected tags in the required format in JSON
local function print_taginfo()
local taginfo = flex.get_taginfo()
local tags = {}

for k, values in pairs(taginfo.main) do
if values[1] == nil or values[1] == 'delete' or values[1] == 'extra' then
for v, group in pairs(values) do
if type(v) == 'string' and group ~= 'delete' and group ~= 'extra' then
local text = 'POI/feature in the search database'
if type(group) ~= 'function' then
text = 'Fallback ' .. text
end
table.insert(tags, get_key_value_description(k, v, text))
end
end
elseif type(values[1]) == 'function' or values[1] == 'fallback' then
local desc = 'POI/feature in the search database'
if values[1] == 'fallback' then
desc = 'Fallback ' .. desc
end
local excp = {}
for v, group in pairs(values) do
if group == 'delete' or group == 'extra' then
table.insert(excp, v)
end
end
if next(excp) ~= nil then
desc = desc .. string.format(' (except for values: %s)',
table.concat(excp, ', '))
end
table.insert(tags, get_key_description(k, desc))
end
end

group_table_to_keys(tags, taginfo.name, NAME_DESCRIPTIONS)
group_table_to_keys(tags, taginfo.address, ADDRESS_DESCRIPTIONS)

local format = {
data_format = 1,
data_url = 'https://nominatim.openstreetmap.org/taginfo.json',
project = {
name = 'Nominatim',
description = 'OSM search engine.',
project_url = 'https://nominatim.openstreetmap.org',
doc_url = 'https://nominatim.org/release-docs/develop/',
contact_name = 'Sarah Hoffmann',
contact_email = '[email protected]'
}
}
format.tags = tags

set_keyorder(format, {'data_format', 'data_url', 'project', 'tags'})
set_keyorder(format.project, {'name', 'description', 'project_url', 'doc_url',
'contact_name', 'contact_email'})

print(json.encode(format))
end

print_taginfo()
Loading

0 comments on commit 9058dab

Please sign in to comment.