Lua config throwing error in metamethods?

140 Views Asked by At

getting the following error when attempting to load data into pgsql database with osm2pgsql:

ERROR: Failed to execute Lua function 'osm2pgsql.process_node': test.lua:183: unknown field 'as_point'
stack traceback:
    [C]: in function 'error'
    [string "..."]:178: in metamethod '__index'

The associated line 178 is just inside the tables.node:insert() method calling the geom = object:as_point().

The only thing I can think of is the limited resources available (i.e. a rpi with 1gb of memory but the osm.pbf file is quite small as well.)

Any help is appreciated.

1

There are 1 best solutions below

0
Jonas Frei On

The as_point function seems to been added in a newer version. I am currently using the version 1.6.0 and therefore had to adjust my lua script a bit. You can find the old syntax via the osm2pgsql git history.

Example lua script that works in version 1.6.0:

local tables = {}

tables.public_transport_stop = osm2pgsql.define_table({
    name = 'public_transport_stop',
    ids = { type = 'node', id_column = 'osm_id' },
    columns = {
        { column = 'tags', type = 'jsonb' },
        { column = 'geom', type = 'point', projection = 4326, not_null = true },
    },
    schema = 'osm'
})

function osm2pgsql.process_node(object)
    if object.tags.railway == 'station' then
        tables.public_transport_stop:add_row({
            tags = object.tags
        })
    end
end