roads.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. -- Defineerime tabeli teede jaoks
  2. local tables = {}
  3. -- Määrame skeemi keskkonnamuutujast või vaikimisi 'public'
  4. local schema = os.getenv("PGSCHEMA") or "public"
  5. -- Lubatud teede tüübid
  6. local allowed_types = {
  7. residential = true,
  8. primary = true,
  9. secondary = true,
  10. tertiary = true,
  11. secondary_link = true,
  12. primary_link = true,
  13. track = true,
  14. service = true,
  15. unclassified = true
  16. }
  17. tables.roads = osm2pgsql.define_way_table('roads', {
  18. { column = 'name', type = 'text' },
  19. { column = 'highway', type = 'text' },
  20. { column = 'surface', type = 'text' },
  21. { column = 'geom', type = 'linestring' }
  22. }, {
  23. schema = schema,
  24. proj = 3301
  25. })
  26. -- Töötleme teed (ways)
  27. function osm2pgsql.process_way(object)
  28. local highway = object.tags.highway
  29. -- Lisa ainult lubatud tüübid, millel on korrektne geomeetria
  30. if highway and highway ~= '' and allowed_types[highway] then
  31. local geom = object:as_linestring()
  32. if geom then
  33. tables.roads:insert({
  34. name = object.tags.name,
  35. highway = highway,
  36. surface = object.tags.surface,
  37. geom = geom
  38. })
  39. end
  40. end
  41. end