Skip to content

Commit 4d0044a

Browse files
authored
Import additional yard fields (#675)
Fixes #662 Tested on http://localhost:8000/#view=14.97/31.1833/-82.38589 at Waycross. <img width="1420" height="929" alt="image" src="https://github.com/user-attachments/assets/2b371d62-8054-47b6-a3fa-2e39eae2c934" />
1 parent d00e807 commit 4d0044a

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

import/openrailwaymap.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ local stations = osm2pgsql.define_table({
253253
{ column = 'operator', type = 'text' },
254254
{ column = 'network', type = 'text' },
255255
{ column = 'position', sql_type = 'text[]' },
256+
{ column = 'yard_purpose', sql_type = 'text[]' },
257+
{ column = 'yard_hump', type = 'boolean' },
256258
{ column = 'wikidata', type = 'text' },
257259
{ column = 'wikimedia_commons', type = 'text' },
258260
{ column = 'wikimedia_commons_file', type = 'text' },
@@ -985,6 +987,8 @@ function osm2pgsql.process_node(object)
985987
operator = tags.operator,
986988
network = tags.network,
987989
position = to_sql_array(map(parse_railway_positions(position, position_exact, line_positions), format_railway_position)),
990+
yard_purpose = split_semicolon_to_sql_array(tags['railway:yard:purpose']),
991+
yard_hump = tags['railway:yard:hump'] == 'yes' or nil,
988992
wikidata = tags.wikidata,
989993
wikimedia_commons = wikimedia_commons,
990994
wikimedia_commons_file = wikimedia_commons_file,
@@ -1261,6 +1265,8 @@ function osm2pgsql.process_way(object)
12611265
name_tags = name_tags(tags),
12621266
operator = tags.operator,
12631267
network = tags.network,
1268+
yard_purpose = split_semicolon_to_sql_array(tags['railway:yard:purpose']),
1269+
yard_hump = tags['railway:yard:hump'] == 'yes' or nil,
12641270
wikidata = tags.wikidata,
12651271
wikimedia_commons = wikimedia_commons,
12661272
wikimedia_commons_file = wikimedia_commons_file,

import/sql/get_station_importance.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS grouped_stations_with_route_count AS
219219
array_remove(array_agg(DISTINCT s.mapillary ORDER BY s.mapillary), null) as mapillary,
220220
array_remove(array_agg(DISTINCT s.note ORDER BY s.note), null) as note,
221221
array_remove(array_agg(DISTINCT s.description ORDER BY s.description), null) as description,
222+
array_remove(string_to_array(array_to_string(array_agg(DISTINCT array_to_string(s.yard_purpose, U&'\\001E')), U&'\\001E'), U&'\\001E'), null) as yard_purpose,
223+
bool_or(s.yard_hump) as yard_hump,
222224
-- Aggregated route count columns
223225
max(sr.route_count) as route_count,
224226
-- Re-grouped clustered stations columns

import/sql/tile_views.sql

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ CREATE OR REPLACE VIEW railway_text_stations AS
391391
nullif(array_to_string(mapillary, U&'\001E'), '') as mapillary,
392392
nullif(array_to_string(wikipedia, U&'\001E'), '') as wikipedia,
393393
nullif(array_to_string(note, U&'\001E'), '') as note,
394-
nullif(array_to_string(description, U&'\001E'), '') as description
394+
nullif(array_to_string(description, U&'\001E'), '') as description,
395+
nullif(array_to_string(yard_purpose, U&'\001E'), '') as yard_purpose,
396+
yard_hump
395397
FROM grouped_stations_with_route_count
396398
ORDER BY
397399
rank DESC NULLS LAST,
@@ -429,7 +431,9 @@ RETURN (
429431
mapillary,
430432
wikipedia,
431433
note,
432-
description
434+
description,
435+
yard_purpose,
436+
yard_hump
433437
FROM railway_text_stations
434438
WHERE way && ST_TileEnvelope(z, x, y)
435439
AND feature = 'station'
@@ -470,7 +474,9 @@ DO $do$ BEGIN
470474
"mapillary": "string",
471475
"wikipedia": "string",
472476
"note": "string",
473-
"description": "string"
477+
"description": "string",
478+
"yard_purpose": "string",
479+
"yard_hump": "boolean"
474480
}
475481
}
476482
]
@@ -510,7 +516,9 @@ RETURN (
510516
mapillary,
511517
wikipedia,
512518
note,
513-
description
519+
description,
520+
yard_purpose,
521+
yard_hump
514522
FROM railway_text_stations
515523
WHERE way && ST_TileEnvelope(z, x, y)
516524
AND feature = 'station'
@@ -549,7 +557,9 @@ DO $do$ BEGIN
549557
"mapillary": "string",
550558
"wikipedia": "string",
551559
"note": "string",
552-
"description": "string"
560+
"description": "string",
561+
"yard_purpose": "string",
562+
"yard_hump": "boolean"
553563
}
554564
}
555565
]
@@ -691,7 +701,9 @@ RETURN (
691701
mapillary,
692702
wikipedia,
693703
note,
694-
description
704+
description,
705+
yard_purpose,
706+
yard_hump
695707
FROM railway_text_stations
696708
WHERE way && ST_TileEnvelope(z, x, y)
697709
AND name IS NOT NULL
@@ -728,7 +740,9 @@ DO $do$ BEGIN
728740
"mapillary": "string",
729741
"wikipedia": "string",
730742
"note": "string",
731-
"description": "string"
743+
"description": "string",
744+
"yard_purpose": "string",
745+
"yard_hump": "boolean"
732746
}
733747
}
734748
]

import/test/test_import_station.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ assert.eq(osm2pgsql.get_and_clear_imported_data(), {
8383
},
8484
})
8585

86+
osm2pgsql.process_node({
87+
tags = {
88+
['railway'] = 'yard',
89+
['railway:yard:purpose'] = 'transloading;manifest',
90+
['railway:yard:hump'] = 'yes',
91+
},
92+
as_point = function () end,
93+
})
94+
assert.eq(osm2pgsql.get_and_clear_imported_data(), {
95+
stations = {
96+
{ feature = 'yard', state = 'present', station = 'train', name_tags = {}, yard_hump = true, yard_purpose = '{"transloading","manifest"}' },
97+
},
98+
})
99+
86100
osm2pgsql.process_node({
87101
tags = {
88102
['abandoned:railway'] = 'junction',

proxy/js/features.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ const stationFeatures = {
311311
position: {
312312
name: 'Position',
313313
},
314+
yard_purpose: {
315+
name: 'Yard purpose',
316+
},
317+
yard_hump: {
318+
name: 'Yard hump',
319+
},
314320
wikidata: {
315321
name: 'Wikidata',
316322
link: links.wikidata,

0 commit comments

Comments
 (0)