places.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. -- Määrame skeemi keskkonnamuutujast või vaikimisi 'public'
  2. local schema = os.getenv("PGSCHEMA") or "public"
  3. -- This config example file is released into the Public Domain.
  4. -- This example shows how you can use JSON and JSONB columns in your database.
  5. local places = osm2pgsql.define_node_table('places', {
  6. { column = 'tags', type = 'jsonb' },
  7. { column = 'geom', type = 'point' },
  8. }, {
  9. schema = schema,
  10. proj = 3301
  11. })
  12. local function starts_with(str, start)
  13. return str:sub(1, #start) == start
  14. end
  15. function osm2pgsql.process_node(object)
  16. if not object.tags.place then
  17. return
  18. end
  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. if has_names then
  36. object.tags.names = names
  37. end
  38. -- The population should be stored as number, not as a string
  39. if object.tags.population then
  40. object.tags.population = tonumber(object.tags.population)
  41. end
  42. places:insert({
  43. tags = object.tags,
  44. geom = object:as_point()
  45. })
  46. end