0

I'm trying to follow https://osm2pgsql.org/examples/buildings/ to import building polygons into a Postgres DB.

I have downloaded a pbf file from https://download.geofabrik.de/europe.html. Specifically, I want to process https://download.geofabrik.de/europe-latest.osm.pbf, but I'm starting out by trying to use the smaller https://download.geofabrik.de/europe/united-kingdom-latest.osm.pbf.

I already have a buildings table with an out of date extract, so I'm trying to publish the new data into a new table name. This is my buildings.lua:

local buildings = osm2pgsql.define_area_table('buildings_2024_03', {
    -- Define an autoincrementing id column, QGIS likes a unique id on the table
    { column = 'id', sql_type = 'serial', create_only = true },
    { column = 'geom', type = 'polygon', not_null = true },
}, { indexes = {
    -- So we get an index on the id column
    { column = 'id', method = 'btree', unique = true },
    -- If we define any indexes we don't get the default index on the geometry
    -- column, so we add it here.
    { column = 'geom', method = 'gist' }
}})

function osm2pgsql.process_way(object)
    if object.is_closed and object.tags.building then
        buildings:insert({
            geom = object:as_polygon()
        })
    end
end

function osm2pgsql.process_relation(object)
    if object.tags.type == 'multipolygon' and object.tags.building then
        -- From the relation we get multipolygons...
        local mp = object:as_multipolygon()
        -- ...and split them into polygons which we insert into the table
        for geom in mp:geometries() do
            buildings:insert({
                geom = geom
            })
        end
    end
end

I'm running the following command (with user/password/host/dbname filled in with real values):

> osm2pgsql -O flex -S buildings.lua -d postgresql://user:password
@host:5432/dbname united-kingdom-latest.osm.pbf
2024-03-26 11:10:45  osm2pgsql version 1.4.1
2024-03-26 11:10:45  Database version: 14.10
2024-03-26 11:10:45  PostGIS version: 3.1
2024-03-26 11:10:45  Node-cache: cache=800MB, maxblocks=12800*65536, allocation method=1
2024-03-26 11:10:45  node cache: stored: 0(0.00%), storage efficiency: 0.00% (dense blocks: 0, sparse nodes: 0), hit rate: 0.00%
2024-03-26 11:10:45  ERROR: Error loading lua config: [string "..."]:14: Error in 'define_table': Column entry must contain a 'type' string field.

How can I fix this error Column entry must contain a 'type' string field.? I don't understand why I'm hitting this error when I'm trying to so closely follow the instructions on https://osm2pgsql.org/examples/buildings/.

1 Answer 1

1

The root cause of my issue was osm2pgsql version 1.4.1

I was running in a debian bullseye container and the osm2pgsql package on this platform is very old and incompatible. I upgraded to debian bookworm and now https://osm2pgsql.org/examples/buildings/ is working as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.