File: test_output_flex_uni.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 (87 lines) | stat: -rw-r--r-- 2,206 bytes parent folder | download | duplicates (4)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

-- Table with a single id column
local table1idcol = osm2pgsql.define_table{
    name = 'osm2pgsql_test_data1',
    ids = { type = 'any', id_column = 'the_id' },
    columns = {
        { column = 'orig_id', type = 'int8' },
        { column = 'tags', type = 'hstore' },
        { column = 'geom', type = 'geometry', not_null = true },
    }
}

-- Table with two id columns: type and id
local table2idcol = osm2pgsql.define_table{
    name = 'osm2pgsql_test_data2',
    ids = { type = 'any', type_column = 'x_type', id_column = 'x_id' },
    columns = {
        { column = 'tags', type = 'hstore' },
        { column = 'geom', type = 'geometry', not_null = true },
    }
}

local function is_empty(some_table)
    return next(some_table) == nil
end

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

    table1idcol:insert({
        orig_id = object.id,
        tags = object.tags,
        geom = object:as_point()
    })
    table2idcol:insert({
        tags = object.tags,
        geom = object:as_point()
    })
end

function osm2pgsql.process_way(object)
    if is_empty(object.tags) then
        return
    end

    if object.tags.building then
        table1idcol:insert({
            orig_id = object.id,
            tags = object.tags,
            geom = object:as_polygon()
        })
        table2idcol:insert({
            tags = object.tags,
            geom = object:as_polygon()
        })
    else
        table1idcol:insert({
            orig_id = object.id,
            tags = object.tags,
            geom = object:as_linestring()
        })
        table2idcol:insert({
            tags = object.tags,
            geom = object:as_linestring()
        })
    end
end

function osm2pgsql.process_relation(object)
    if object.tags.type == 'multipolygon' then
        local mgeom = object:as_multipolygon()
        for sgeom in mgeom:geometries() do
            table1idcol:insert({
                orig_id = object.id,
                tags = object.tags,
                geom = sgeom
            })
            table2idcol:insert({
                tags = object.tags,
                geom = sgeom
            })
        end
    end
end