combined.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. local tables = {}
  2. local schema = os.getenv("PGSCHEMA") or "public"
  3. -- Tabel halduspiirkondadele
  4. tables.admin = osm2pgsql.define_area_table('administrative_polygon', {
  5. { column = 'name', type = 'text' },
  6. { column = 'admin_level', type = 'text' },
  7. { column = 'boundary', type = 'text' },
  8. { column = 'geom', type = 'geometry' }
  9. }, {
  10. schema = schema,
  11. proj = 3301
  12. })
  13. -- Tabel teedele
  14. tables.roads = osm2pgsql.define_way_table('roads', {
  15. { column = 'name', type = 'text' },
  16. { column = 'highway', type = 'text' },
  17. { column = 'surface', type = 'text' },
  18. { column = 'geom', type = 'linestring' }
  19. }, {
  20. schema = schema,
  21. proj = 3301
  22. })
  23. -- Halduspiirkondade töötlemine
  24. function osm2pgsql.process_area(object)
  25. print(">> process_area called for relation id:", object.id)
  26. local boundary = object.tags.boundary
  27. local admin_level = object.tags.admin_level
  28. local geom = object:as_polygon()
  29. if boundary == 'administrative' and admin_level and geom then
  30. tables.admin:insert({
  31. name = object.tags.name,
  32. admin_level = admin_level,
  33. boundary = boundary,
  34. geom = geom
  35. })
  36. end
  37. end
  38. -- Teede töötlemine
  39. local allowed_types = {
  40. residential = true,
  41. primary = true,
  42. secondary = true,
  43. tertiary = true,
  44. secondary_link = true,
  45. primary_link = true,
  46. track = true,
  47. service = true,
  48. unclassified = true
  49. }
  50. function osm2pgsql.process_way(object)
  51. local highway = object.tags.highway
  52. if highway and highway ~= '' and allowed_types[highway] then
  53. local geom = object:as_linestring()
  54. if geom then
  55. tables.roads:insert({
  56. name = object.tags.name,
  57. highway = highway,
  58. surface = object.tags.surface,
  59. geom = geom
  60. })
  61. end
  62. end
  63. end