Lua配置在元方法中引发错误?

huangapple go评论76阅读模式
英文:

Lua config throwing error in metamethods?

问题

在尝试使用osm2pgsql将数据加载到pgsql数据库时遇到以下错误:

错误:执行Lua函数'osm2pgsql.process_node'失败:test.lua:183:未知字段'as_point'
调用堆栈:
	[C]: 在函数'error'中
	[string "..."]:178: 在元方法'__index'中

相关的第178行位于tables.node:insert()方法内,调用了geom = object:as_point()。

我能想到的唯一可能原因是资源有限(即只有1GB内存的树莓派,但osm.pbf文件也相当小)。

感谢任何帮助。

英文:

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

得分: 1

as_point 函数似乎是在更新的版本中添加的。我目前使用的版本是 1.6.0,因此必须稍微调整我的 Lua 脚本。你可以在 osm2pgsql git 历史记录 中找到旧的语法。

在版本 1.6.0 中有效的 Lua 脚本示例:

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
}
英文:

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

huangapple
  • 本文由 发表于 2023年3月10日 00:00:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687110.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定