From 117802c1db2c8e2daab7ca2fdecc47baf3adadc2 Mon Sep 17 00:00:00 2001 From: Ryan Lambert Date: Thu, 11 Aug 2022 19:36:51 -0600 Subject: [PATCH 1/4] Update road.lua to use new multiline functionality. --- flex-config/style/road.lua | 81 ++++++++++++++++++- tests/expected/road_line_aggregates.out | 2 +- tests/expected/road_line_osm_type_count.out | 4 +- .../expected/road_polygon_osm_type_count.out | 5 +- 4 files changed, 86 insertions(+), 6 deletions(-) diff --git a/flex-config/style/road.lua b/flex-config/style/road.lua index 84379aa..74dc29c 100644 --- a/flex-config/style/road.lua +++ b/flex-config/style/road.lua @@ -40,7 +40,7 @@ tables.road_line = osm2pgsql.define_table({ { column = 'route_cycle', type = 'boolean' }, { column = 'route_motor', type = 'boolean' }, { column = 'access', type = 'text' }, - { column = 'geom', type = 'linestring', projection = srid } + { column = 'geom', type = 'multilinestring', projection = srid } } }) @@ -168,6 +168,71 @@ function road_process_way(object) end +function road_process_relation(object) + if not object.tags.highway then + return + end + + local name = get_name(object.tags) + local route_foot = routable_foot(object.tags) + local route_cycle = routable_cycle(object.tags) + local route_motor = routable_motor(object.tags) + + local osm_type = object.tags.highway + local ref = get_ref(object.tags) + + -- in km/hr + local maxspeed = parse_speed(object.tags.maxspeed) + + -- results in nil for reversible and alternating + local oneway = object.tags.oneway or 0 + + local major = major_road(osm_type) + local layer = parse_layer_value(object.tags.layer) + local tunnel = object.tags.tunnel + local bridge = object.tags.bridge + local access = object.tags.access + + if object.tags.area == 'yes' + or object.tags.indoor == 'room' + then + tables.road_polygon:add_row({ + name = name, + osm_type = osm_type, + ref = ref, + maxspeed = maxspeed, + major = major, + layer = layer, + tunnel = tunnel, + bridge = bridge, + route_foot = route_foot, + route_cycle = route_cycle, + route_motor = route_motor, + access = access, + geom = { create = 'area' } + }) + else + tables.road_line:add_row({ + name = name, + osm_type = osm_type, + ref = ref, + maxspeed = maxspeed, + oneway = oneway, + major = major, + layer = layer, + tunnel = tunnel, + bridge = bridge, + route_foot = route_foot, + route_cycle = route_cycle, + route_motor = route_motor, + access = access, + geom = { create = 'line' } + }) + end + +end + + if osm2pgsql.process_node == nil then -- Change function name here osm2pgsql.process_node = road_process_node @@ -194,3 +259,17 @@ else road_process_way(object_copy) end end + + +if osm2pgsql.process_relation == nil then + osm2pgsql.process_relation = road_process_relation +else + local nested = osm2pgsql.process_relation + osm2pgsql.process_relation = function(object) + local object_copy = deep_copy(object) + nested(object) + -- Change function name here + road_process_relation(object_copy) + end + +end diff --git a/tests/expected/road_line_aggregates.out b/tests/expected/road_line_aggregates.out index ca9f8b6..24d7fd4 100644 --- a/tests/expected/road_line_aggregates.out +++ b/tests/expected/road_line_aggregates.out @@ -1 +1 @@ -34634|1139|6880|26064|22080|24424 +34645|1139|6880|26075|22080|24424 diff --git a/tests/expected/road_line_osm_type_count.out b/tests/expected/road_line_osm_type_count.out index 8c68a38..fda73c9 100644 --- a/tests/expected/road_line_osm_type_count.out +++ b/tests/expected/road_line_osm_type_count.out @@ -1,12 +1,12 @@ construction|7 cycleway|259 elevator|1 -footway|7381 +footway|7383 living_street|24 motorway|476 motorway_link|401 path|551 -pedestrian|38 +pedestrian|47 primary|2549 primary_link|264 proposed|11 diff --git a/tests/expected/road_polygon_osm_type_count.out b/tests/expected/road_polygon_osm_type_count.out index 0c145c0..b9d5e45 100644 --- a/tests/expected/road_polygon_osm_type_count.out +++ b/tests/expected/road_polygon_osm_type_count.out @@ -1,7 +1,8 @@ +bridleway|1 elevator|3 -footway|25 +footway|29 living_street|1 -pedestrian|55 +pedestrian|76 service|1 services|1 steps|1 From 1c0b1c48b764df54f7e137d1c1ef9b0e5cab5fdd Mon Sep 17 00:00:00 2001 From: Ryan Lambert Date: Thu, 11 Aug 2022 19:59:41 -0600 Subject: [PATCH 2/4] Update road_major and public_transport with multiline --- flex-config/style/public_transport.lua | 21 ++++++- flex-config/style/road_major.lua | 59 ++++++++++++++++++- .../public_transport_line_osm_type_count.out | 1 + 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/flex-config/style/public_transport.lua b/flex-config/style/public_transport.lua index f9e134b..740f3d8 100644 --- a/flex-config/style/public_transport.lua +++ b/flex-config/style/public_transport.lua @@ -48,7 +48,7 @@ tables.public_transport_line = osm2pgsql.define_table({ { column = 'lit', type = 'text' }, { column = 'wheelchair', type = 'text'}, { column = 'wheelchair_desc', type = 'text'}, - { column = 'geom', type = 'linestring', projection = srid } + { column = 'geom', type = 'multilinestring', projection = srid } } }) @@ -292,6 +292,25 @@ function public_transport_process_relation(object) wheelchair_desc = wheelchair_desc, geom = { create = 'area' } }) + else + tables.public_transport_line:add_row({ + osm_type = osm_types.osm_type, + osm_subtype = osm_types.osm_subtype, + public_transport = public_transport, + name = name, + ref = ref, + operator = operator, + layer = layer, + network = network, + surface = surface, + bus = bus, + shelter = shelter, + bench = bench, + lit = lit, + wheelchair = wheelchair, + wheelchair_desc = wheelchair_desc, + geom = { create = 'line' } + }) end end diff --git a/flex-config/style/road_major.lua b/flex-config/style/road_major.lua index aab600a..9319635 100644 --- a/flex-config/style/road_major.lua +++ b/flex-config/style/road_major.lua @@ -15,7 +15,7 @@ tables.road_major = osm2pgsql.define_table({ { column = 'tunnel', type = 'text' }, { column = 'bridge', type = 'text' }, { column = 'major', type = 'boolean', not_null = true}, - { column = 'geom', type = 'linestring', projection = srid }, + { column = 'geom', type = 'multilinestring', projection = srid }, } }) @@ -56,6 +56,48 @@ function road_major_process_way(object) end +function road_major_process_relation(object) + if not object.tags.highway then + return + end + + if not major_road(object.tags.highway) then + return + end + + local major = true + + local name = get_name(object.tags) + local osm_type = object.tags.highway + local ref = get_ref(object.tags) + + -- in km/hr + local maxspeed = parse_speed(object.tags.maxspeed) + + -- results in nil for reversible and alternating + local oneway = object.tags.oneway or 0 + + local layer = parse_layer_value(object.tags.layer) + local tunnel = object.tags.tunnel + local bridge = object.tags.bridge + local access = object.tags.access + + tables.road_line:add_row({ + name = name, + osm_type = osm_type, + ref = ref, + maxspeed = maxspeed, + oneway = oneway, + major = major, + layer = layer, + tunnel = tunnel, + bridge = bridge, + access = access, + geom = { create = 'line' } + }) + +end + if osm2pgsql.process_way == nil then osm2pgsql.process_way = road_major_process_way else @@ -66,3 +108,18 @@ else road_major_process_way(object_copy) end end + + + +if osm2pgsql.process_relation == nil then + osm2pgsql.process_relation = road_major_process_relation +else + local nested = osm2pgsql.process_relation + osm2pgsql.process_relation = function(object) + local object_copy = deep_copy(object) + nested(object) + -- Change function name here + road_major_process_relation(object_copy) + end + +end diff --git a/tests/expected/public_transport_line_osm_type_count.out b/tests/expected/public_transport_line_osm_type_count.out index b7156ed..59617e3 100644 --- a/tests/expected/public_transport_line_osm_type_count.out +++ b/tests/expected/public_transport_line_osm_type_count.out @@ -1,6 +1,7 @@ aerialway|animal_crossing|1 railway|abandoned|31 railway|disused|22 +railway|facility|18 railway|light_rail|2 railway|rail|512 railway|subway|225 From b7a7474fe8b4e8c072893990c0e72529a694f1f3 Mon Sep 17 00:00:00 2001 From: Ryan Lambert Date: Thu, 11 Aug 2022 20:08:14 -0600 Subject: [PATCH 3/4] Update water layer with relation processing --- flex-config/style/water.lua | 100 +++++++++++++++++- .../water_line_osm_type_subtype_count.out | 4 +- .../water_polygon_osm_type_subtype_count.out | 2 +- 3 files changed, 102 insertions(+), 4 deletions(-) diff --git a/flex-config/style/water.lua b/flex-config/style/water.lua index 3a05958..c75b129 100644 --- a/flex-config/style/water.lua +++ b/flex-config/style/water.lua @@ -31,7 +31,7 @@ tables.water_line = osm2pgsql.define_table({ { column = 'tunnel', type = 'text' }, { column = 'bridge', type = 'text' }, { column = 'boat', type = 'text' }, - { column = 'geom', type = 'linestring' , projection = srid}, + { column = 'geom', type = 'multilinestring' , projection = srid}, } }) @@ -197,6 +197,92 @@ function water_process_way(object) end +end + + +function water_process_relation(object) + if not object.tags.natural + and not object.tags.waterway then + return + end + + if object.tags.natural == 'water' + or object.tags.natural == 'lake' + or object.tags.natural == 'hot_spring' + or object.tags.natural == 'waterfall' + or object.tags.natural == 'wetland' + or object.tags.natural == 'swamp' + or object.tags.natural == 'water_meadow' + or object.tags.natural == 'waterway' + or object.tags.natural == 'spring' + then + local osm_type = 'natural' + local osm_subtype = object:grab_tag('natural') + local name = get_name(object.tags) + local layer = parse_layer_value(object.tags.layer) + local tunnel = object:grab_tag('tunnel') + local bridge = object:grab_tag('bridge') + local boat = object:grab_tag('boat') + + if object.tags.type == 'multipolygon' then + tables.water_polygon:add_row({ + osm_type = osm_type, + osm_subtype = osm_subtype, + name = name, + layer = layer, + tunnel = tunnel, + bridge = bridge, + boat = boat, + geom = { create = 'area' } + }) + else + tables.water_line:add_row({ + osm_type = osm_type, + osm_subtype = osm_subtype, + name = name, + layer = layer, + tunnel = tunnel, + bridge = bridge, + boat = boat, + geom = { create = 'line' } + }) + end + + elseif object.tags.waterway then + local osm_type = 'waterway' + local osm_subtype = object:grab_tag('waterway') + local name = get_name(object.tags) + local layer = parse_layer_value(object.tags.layer) + local tunnel = object:grab_tag('tunnel') + local bridge = object:grab_tag('bridge') + local boat = object:grab_tag('boat') + + if object.tags.type == 'multipolygon' then + tables.water_polygon:add_row({ + osm_type = osm_type, + osm_subtype = osm_subtype, + name = name, + layer = layer, + tunnel = tunnel, + bridge = bridge, + boat = boat, + geom = { create = 'area' } + }) + else + tables.water_line:add_row({ + osm_type = osm_type, + osm_subtype = osm_subtype, + name = name, + layer = layer, + tunnel = tunnel, + bridge = bridge, + boat = boat, + geom = { create = 'line' } + }) + end + + end + end @@ -228,3 +314,15 @@ else water_process_way(object_copy) end end + + +if osm2pgsql.process_relation == nil then + osm2pgsql.process_relation = water_process_relation +else + local nested = osm2pgsql.process_relation + osm2pgsql.process_relation = function(object) + local object_copy = deep_copy(object) + nested(object) + water_process_relation(object_copy) + end +end diff --git a/tests/expected/water_line_osm_type_subtype_count.out b/tests/expected/water_line_osm_type_subtype_count.out index 01135c0..fa0c6c8 100644 --- a/tests/expected/water_line_osm_type_subtype_count.out +++ b/tests/expected/water_line_osm_type_subtype_count.out @@ -1,8 +1,8 @@ -waterway|canal|15 +waterway|canal|16 waterway|dam|2 waterway|derelict_canal|2 waterway|ditch|5 waterway|drain|2 -waterway|river|13 +waterway|river|16 waterway|stream|113 waterway|weir|2 diff --git a/tests/expected/water_polygon_osm_type_subtype_count.out b/tests/expected/water_polygon_osm_type_subtype_count.out index 16243ec..4e31cd7 100644 --- a/tests/expected/water_polygon_osm_type_subtype_count.out +++ b/tests/expected/water_polygon_osm_type_subtype_count.out @@ -1,4 +1,4 @@ -natural|water|260 +natural|water|274 natural|wetland|13 waterway|dock|2 waterway|riverbank|5 From 9b67a8c216cf307ef5de993d3a1e5e0afa0ebf3b Mon Sep 17 00:00:00 2001 From: Ryan Lambert Date: Thu, 11 Aug 2022 20:48:22 -0600 Subject: [PATCH 4/4] Remove columns that do not exist from road_major --- flex-config/style/road_major.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flex-config/style/road_major.lua b/flex-config/style/road_major.lua index 9319635..fab3e41 100644 --- a/flex-config/style/road_major.lua +++ b/flex-config/style/road_major.lua @@ -82,17 +82,15 @@ function road_major_process_relation(object) local bridge = object.tags.bridge local access = object.tags.access - tables.road_line:add_row({ + tables.road_major:add_row({ name = name, osm_type = osm_type, ref = ref, maxspeed = maxspeed, - oneway = oneway, major = major, layer = layer, tunnel = tunnel, bridge = bridge, - access = access, geom = { create = 'line' } })