File: unitable.lua

package info (click to toggle)
osm2pgsql 1.4.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,124 kB
  • sloc: cpp: 41,466; ansic: 1,366; python: 564; sh: 19; makefile: 15
file content (72 lines) | stat: -rw-r--r-- 1,942 bytes parent folder | download
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- This config example file is released into the Public Domain.

-- Put all OSM data into a single table

-- inspect = require('inspect')

-- We define a single table that can take any OSM object and any geometry.
-- XXX expire will currently not work on these tables.
local dtable = osm2pgsql.define_table{
    name = "data",
    -- This will generate a column "osm_id INT8" for the id, and a column
    -- "osm_type CHAR(1)" for the type of object: N(ode), W(way), R(relation)
    ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
    columns = {
        { column = 'attrs', type = 'hstore' },
        { column = 'tags',  type = 'hstore' },
        { column = 'geom',  type = 'geometry' },
    }
}

-- print("columns=" .. inspect(dtable:columns()))

-- Helper function to remove some of the tags we usually are not interested in.
-- Returns true if there are no tags left.
function clean_tags(tags)
    tags.odbl = nil
    tags.created_by = nil
    tags.source = nil
    tags['source:ref'] = nil

    return next(tags) == nil
end

function process(object, geometry_type)
    if clean_tags(object.tags) then
        return
    end
    dtable:add_row({
        attrs = {
            version = object.version,
            timestamp = object.timestamp,
        },
        tags = object.tags,
        geom = { create = geometry_type }
    })
end

function osm2pgsql.process_node(object)
    process(object, 'point')
end

function osm2pgsql.process_way(object)
    process(object, 'line')
end

function osm2pgsql.process_relation(object)
    if clean_tags(object.tags) then
        return
    end

    if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then
        dtable:add_row({
            attrs = {
                version = object.version,
                timestamp = object.timestamp,
            },
            tags = object.tags,
            geom = { create = 'area' }
        })
    end
end