1-- This config example file is released into the Public Domain. 2 3-- This example shows how you can use JSON and JSONB columns in your database. 4 5local places = osm2pgsql.define_node_table('places', { 6 { column = 'tags', type = 'jsonb' }, 7 { column = 'geom', type = 'point' }, 8}) 9 10local function starts_with(str, start) 11 return str:sub(1, #start) == start 12end 13 14function osm2pgsql.process_node(object) 15 if not object.tags.place then 16 return 17 end 18 19 -- Put all name:* tags in their own substructure 20 local names = {} 21 local has_names = false 22 for k, v in pairs(object.tags) do 23 if k == 'name' then 24 names[''] = v 25 object.tags.name = nil 26 has_names = true 27 elseif starts_with(k, "name:") then 28 -- extract language 29 local lang = k:sub(6, -1) 30 names[lang] = v 31 object.tags[k] = nil 32 has_names = true 33 end 34 end 35 36 if has_names then 37 object.tags.names = names 38 end 39 40 -- The population should be stored as number, not as a string 41 if object.tags.population then 42 object.tags.population = tonumber(object.tags.population) 43 end 44 45 places:add_row({ 46 tags = object.tags 47 }) 48end 49 50