File: places.lua

package info (click to toggle)
osm2pgsql 2.1.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,652 kB
  • sloc: cpp: 59,934; python: 1,039; ansic: 763; sh: 25; makefile: 14
file content (50 lines) | stat: -rw-r--r-- 1,283 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- This config example file is released into the Public Domain.

-- This example shows how you can use JSON and JSONB columns in your database.

local places = osm2pgsql.define_node_table('places', {
    { column = 'tags', type = 'jsonb' },
    { column = 'geom', type = 'point' },
})

local function starts_with(str, start)
   return str:sub(1, #start) == start
end

function osm2pgsql.process_node(object)
    if not object.tags.place then
        return
    end

    -- Put all name:* tags in their own substructure
    local names = {}
    local has_names = false
    for k, v in pairs(object.tags) do
        if k == 'name' then
            names[''] = v
            object.tags.name = nil
            has_names = true
        elseif starts_with(k, "name:") then
            -- extract language
            local lang = k:sub(6, -1)
            names[lang] = v
            object.tags[k] = nil
            has_names = true
        end
    end

    if has_names then
        object.tags.names = names
    end

    -- The population should be stored as number, not as a string
    if object.tags.population then
        object.tags.population = tonumber(object.tags.population)
    end

    places:insert({
        tags = object.tags,
        geom = object:as_point()
    })
end