Skip to content

Instantly share code, notes, and snippets.

@mvexel
Created November 17, 2025 17:36
Show Gist options
  • Select an option

  • Save mvexel/7e9349a32a962764d908bb74ee08d924 to your computer and use it in GitHub Desktop.

Select an option

Save mvexel/7e9349a32a962764d908bb74ee08d924 to your computer and use it in GitHub Desktop.
-- Define shops table
local shops = osm2pgsql.define_table({
name = 'shops',
ids = {
type = 'any',
id_column = 'osm_id',
type_column = 'osm_type'
},
columns = {
{
column = 'name',
type = 'text'
},
{
column = 'address',
type = 'text'
},
{
column = 'type',
type = 'text'
},
{
column = 'tags',
type = 'jsonb'
},
{
column = 'geom',
type = 'point',
projection = 4326,
not_null = true
}
}
})
-- Helper function to concatenate address parts from OSM tag values
local function concat_address(tags)
local address = ''
for _, part in ipairs({
'street',
'house_number',
'postcode',
'city'
}) do
part = tags["addr:" .. part]
if part and part ~= '' then
address = address .. part .. ' '
end
end
-- Trim leading/trailing spaces
return address:match("^%s*(.-)%s*$")
end
function osm2pgsql.process_node(object)
local address = concat_address(object.tags)
if object.tags.shop then
shops:insert({
name = object.tags.name,
address = address,
type = object.tags.shop,
tags = object.tags,
geom = object:as_point()
})
end
end
function osm2pgsql.process_way(object)
local address = concat_address(object.tags)
if object.is_closed then
if object.tags.shop then
shops:insert({
name = object.tags.name,
address = address,
type = object.tags.shop,
tags = object.tags,
geom = object:as_polygon():centroid()
})
end
end
end
function osm2pgsql.process_relation(object)
local address = concat_address(object.tags)
if object.tags.type == 'multipolygon' then
if object.tags.shop then
shops:insert({
name = object.tags.name,
address = address,
type = object.tags.shop,
tags = object.tags,
geom = object:as_multipolygon():centroid()
})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment