Skip to content

Commit 2eb85bc

Browse files
authored
Update yards with their landuse (#688)
Closes #662 Yard nodes which are contained in a landuse=railway area, assume the landuse area as yard geometry. Requires full planet data re-import. Example: https://www.openstreetmap.org/node/9196070580 Before, after: <img width="427" height="622" alt="image" src="https://github.com/user-attachments/assets/46fa57e6-8fc3-49e9-bda0-ea47552aaba3" /> <img width="427" height="622" alt="image" src="https://github.com/user-attachments/assets/1fec9c6c-1114-4047-a9f7-ff788ea8a138" />
1 parent 0878141 commit 2eb85bc

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

import/docker-startup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ function reduce_data() {
7777
$PSQL -c "delete from platforms p where not exists(select * from routes r where r.platform_ref_ids @> Array[p.osm_id]) and not exists(select * from railway_line l where st_dwithin(p.way, l.way, 20));"
7878
}
7979

80+
function transform_data() {
81+
# Yard nodes which are contained in a landuse=railway area, assume the landuse area as yard geometry.
82+
$PSQL -c "update stations s set way = l.way from landuse l where ST_Within(s.way, l.way) and feature = 'yard' and GeometryType(s.way) = 'POINT' and s.osm_type = 'N';"
83+
}
84+
8085
function create_update_functions_views() {
8186
echo "Post processing imported data"
8287
$PSQL -f sql/tile_functions.sql
@@ -117,6 +122,7 @@ import)
117122
enable_disable_extensions
118123
import_db
119124
reduce_data
125+
transform_data
120126
create_update_functions_views
121127
print_summary
122128

import/openrailwaymap.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,15 @@ local stop_area_groups = osm2pgsql.define_table({
526526
},
527527
})
528528

529+
local landuse = osm2pgsql.define_table({
530+
name = 'landuse',
531+
ids = { type = 'way', id_column = 'osm_id' },
532+
columns = {
533+
{ column = 'id', sql_type = 'serial', create_only = true },
534+
{ column = 'way', type = 'polygon' },
535+
},
536+
})
537+
529538
local railway_line_states = {}
530539
-- ordered from lower to higher importance
531540
local states = {'razed', 'abandoned', 'disused', 'proposed', 'construction', 'preserved'}
@@ -1379,6 +1388,12 @@ function osm2pgsql.process_way(object)
13791388
tactile_paving = tags.tactile_paving == 'yes',
13801389
})
13811390
end
1391+
1392+
if tags.landuse == 'railway' then
1393+
landuse:insert({
1394+
way = object:as_polygon(),
1395+
})
1396+
end
13821397
end
13831398

13841399
local route_values = osm2pgsql.make_check_values_func({'train', 'subway', 'tram', 'light_rail'})

import/osmium-tags-filter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ nwr/public_transport=platform
99
n/power=catenary_mast
1010
nw/museum=railway
1111
w/power=catenary_portal
12+
w/landuse=railway
1213
r/public_transport=stop_area
1314
r/public_transport=stop_area_group
1415
r/route=train
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package.path = package.path .. ";test/?.lua"
2+
3+
local assert = require('assert')
4+
5+
-- Global mock
6+
require('mock_osm2psql')
7+
8+
local openrailwaymap = require('openrailwaymap')
9+
10+
local way = {
11+
length = function () return 1 end,
12+
}
13+
14+
-- Landuse
15+
osm2pgsql.process_way({
16+
tags = {
17+
landuse = 'railway',
18+
},
19+
as_polygon = function () return way end,
20+
})
21+
assert.eq(osm2pgsql.get_and_clear_imported_data(), {
22+
landuse = {
23+
{ way = way },
24+
},
25+
})

0 commit comments

Comments
 (0)