motorway-colours.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 file shows how to use a locator to find the country-specific colour
  5. -- Define the "countries" locator and get all country geometries from the
  6. -- database. Use the import-countries.lua file to import them first, before
  7. -- you run this.
  8. local countries = osm2pgsql.define_locator({ name = 'countries' })
  9. countries:add_from_db('SELECT code, ST_Subdivide(geom, 200) FROM '..schema..'.countries')
  10. local highways = osm2pgsql.define_way_table('highways', {
  11. { column = 'hwtype', type = 'text' },
  12. { column = 'country', type = 'text' },
  13. { column = 'colour', type = 'text' },
  14. { column = 'geom', type = 'linestring', not_null = true },
  15. }, {
  16. schema = schema,
  17. proj = 3301
  18. })
  19. -- Each country uses their own colour for motorways. Here is the beginning
  20. -- of a list of some countries in Europe. Source:
  21. -- https://en.wikipedia.org/wiki/Comparison_of_European_road_signs
  22. local cc2colour = {
  23. EE = '#2d00e5',
  24. RU = '#128044',
  25. LT = '#174688',
  26. LV = '#333b97'
  27. }
  28. function osm2pgsql.process_way(object)
  29. if object.tags.highway then
  30. local geom = object:as_linestring()
  31. local cc = countries:first_intersecting(geom)
  32. highways:insert({
  33. hwtype = object.tags.highway,
  34. country = cc,
  35. colour = cc2colour[cc],
  36. geom = geom,
  37. })
  38. end
  39. end